2016-11-08 9 views
0

NSSavePanelを提示せずに編集した画像を保存する方法はありますか?NSSavePanelのないImageKitでココアを保存する

つまり、多くのアプリケーションでは、「保存」または「名前を付けて保存...」というオプションが用意されています。「保存」はファイル名を上書きし、「名前を付けて保存」ではNSSavePanelすべてのオプションがあります。

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

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

ありがとうございます!

答えて

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]; 
    } 
関連する問題