0

ユーザーに NSSavePanel を提示せずに編集した画像を保存する方法はありますか?

つまり、多くのアプリケーションは、ユーザーに「保存」または「名前を付けて保存...」のオプションを提供します。「保存」はファイル名を保持したままファイルを上書きするだけで、「名前を付けて保存...」はすべてのオプションを含む完全な NSSavePanel を表示します。 .

ImageKit を呼び出して画像の編集を可能にするアプリがあり、ユーザーがボタンまたはキー コマンドをクリックして、パネルを必要とせずに保存できるようにしたいと考えています。ダイアログも通知もありません。保存をクリックするだけで、画像ファイルは新しく編集されたもので上書きされます。

この方法でテキスト ファイルを保存する方法は知っていますが、IKImageView から編集された画像についてはわかりません。

前もって感謝します!

4

1 に答える 1

0

そこで、NSSavePanel をすべてバイパスして、GCImageDest に直接移動しました。

- (IBAction)saveWithNoPanel: (id)sender
{
    _saveOptions = [[IKSaveOptions alloc] initWithImageProperties: _imageProperties
                                                      imageUTType: _imageUTType];

    NSString * url=[[NSUserDefaults standardUserDefaults] objectForKey:@"photoPath"];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy"];
    NSString * yearString = [formatter stringFromDate:[NSDate date]];

    NSString * fileName = [[_imageWindow representedFilename] lastPathComponent];
    //NSLog(@"Filename: %@",fileName);
    NSString * photoUrl =[NSString stringWithFormat:@"%@%@%@%@%@",url,@"/",yearString,@"/",fileName];
    //NSLog(@"photourl: %@",photoUrl);

    NSString * newUTType = [_saveOptions imageUTType];
    CGImageRef image;

    image = [_imageView image];

        if (image)
        {
            NSURL * url =[NSURL fileURLWithPath: photoUrl];
            //NSLog(@"URL: %@",url);

            CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)url,
                                                                         (CFStringRef)newUTType, 1, NULL);

            if (dest)
            {
                CGImageDestinationAddImage(dest, image,
                                           (CFDictionaryRef)[_saveOptions imageProperties]);
                CGImageDestinationFinalize(dest);
                CFRelease(dest);
            }
        } else
        {
            NSLog(@"*** saveImageToPath - no image");
        }
    [pwPhotoPathTextField setStringValue:[NSString stringWithFormat:@"%@%@",photoUrl]];
    [_imageWindow orderOut:self];
    }
于 2016-11-08T02:34:43.320 に答える