我试图在 Cocoa 中合并 2 个不同的图像,并喜欢将生成的图像保存在我的应用程序中。到目前为止我所做的是:
-(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];
}
我没有收到任何错误,捆绑包的网址似乎是正确的。并且“数据”包含〜2,9MB 2985448