Reputation: 191
im trying to merge 2 different images in Cocoa and like to save the resulting image in my application. What I've done so far is this:
-(void)mergeImage:(NSImage*)target withImage:(NSImage*)source {
[target lockFocus];
NSPoint aPoint;
aPoint.x = 1;
aPoint.y = 1;
[source drawAtPoint:aPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[target unlockFocus];
NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep alloc]initWithData:[target TIFFRepresentation]];
[target addRepresentation:bmpImageRep];
NSData *data = [bmpImageRep representationUsingType: NSPNGFileType
properties: nil];
NSURL* aURL = [[NSBundle mainBundle] bundleURL];
NSString *tmpPathToFile = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/tempImage.png", aURL]];
[data writeToFile:tmpPathToFile atomically:YES];
}
I don't get any error, the urls to the bundle seem to be correct. And the "data" holds ~2,9MB 2985448
Upvotes: 1
Views: 642
Reputation: 6862
atomically
won't overwrite it.Just like CodaFi mentioned it, you are not allowed to write to the application bundle. You can, however, write to the application support folder. That's what it's there for.
Upvotes: 2