gpt4 book ai didi

iphone - UIGraphicsBeginImageContext,来自应用程序的电子邮件图像

转载 作者:行者123 更新时间:2023-11-29 04:20:02 34 4
gpt4 key购买 nike

我正在尝试附加从 UIGraphicsBeginImageContext 渲染的图像。作为测试,我也将图像添加到相册中。这一切在模拟器上都能完美运行,但在设备上,正确的图像会添加到相册中,但不会正确显示在电子邮件附件中。我认为这是因为它是一个大图像,并且在 iPhone 3gs 上需要一些时间。这意味着我必须检查它是否已完成渲染图像。有办法做到这一点吗?这是我的代码:

UIGraphicsBeginImageContext(backGround.layer.frame.size);
[backGround.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
UIGraphicsEndImageContext();

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
NSData *imgData = UIImagePNGRepresentation(image);
[mailer addAttachmentData:imgData mimeType:@"image/png" fileName:@"myfilename"];

我想知道,也许图像还没有完全完成,当我制作它的 PNG 表示形式时,它仍然有损坏的数据。我可以以某种方式检查 UIImage 是否“完成”吗?

最佳答案

尝试实现完成方法并检查它。一个例子是,

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

- (void)image:(UIImage *) image didFinishSavingWithError:(NSError *) error contextInfo: (void *) contextInfo {
NSLog(@"SAVE IMAGE COMPLETE");
if(error != nil) {
NSLog(@"ERROR SAVING:%@", [error localizedDescription]);
}

}

根据错误消息,您可以调试错误消息。检查UIImageWriteToSavedPhotosAlbum documentation了解更多详情。

关于iphone - UIGraphicsBeginImageContext,来自应用程序的电子邮件图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13092377/

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