gpt4 book ai didi

objective-c - Cocoa合并2张图片并保存

转载 作者:行者123 更新时间:2023-12-03 17:04:25 25 4
gpt4 key购买 nike

我正在尝试在 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];
}

我没有收到任何错误, bundle 的 URL 似乎是正确的。 “数据”保存约 2,9MB 2985448

最佳答案

  1. 您的应用程序是否已沙盒化?如果是这样,请确保它确实允许写入您正在写入的目录。
  2. 是否已有同名文件? 原子不会覆盖它。
  3. 文件路径是否正确?
<小时/>

就像 CodaFi提到它,你不能写入应用程序包。但是,您可以写入应用程序支持文件夹。这就是它的用途。

关于objective-c - Cocoa合并2张图片并保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14006567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com