那么,有没有一种方法可以在不向用户显示NSSavePanel的情况下保存经过编辑的图像?
也就是说,许多应用程序为用户提供了“保存”或“另存为.”的选项。其中"Save“只是覆盖了保存文件名的文件和”另存为.“显示包含所有选项的完整NSSavePanel。
我有一个应用程序调用ImageKit以允许编辑图像,并且我希望允许用户单击按钮或键命令来保存,而不需要面板。没有对话,没有通知,只需单击“保存”,图像文件就会被新编辑的文件覆盖。
我知道如何以这种方式保存文本文件,但我不确定如何从IKImageView中编辑图像。
提前感谢!
发布于 2016-11-08 02:34:43
所以我就一起绕过了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];
}https://stackoverflow.com/questions/40477382
复制相似问题