So is there a way to save an edited image without presenting the user the NSSavePanel?
That is, many applications offer the user the option to either "Save" or "Save As..." where "Save" just overwrites the file keeping the filename and "Save As..." presents the full NSSavePanel with all the options.
I have an app that invokes ImageKit to allow the editing of an image and I'd like to allow the user to click a button or key command to just save without needing the panel. No dialogue, no notification, just click save and the image file is overwritten with the new edited one.
I know how to save a text file this way but I'm not sure about an edited image from an IKImageView.
Thanks in advance!
So I just bypassed the NSSavePanel all together and went right to 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];
}