UIGraphicsBeginImageContext,来自app的电子邮件图片

时间:2012-10-26 18:25:34

标签: iphone ios uiimage

我正在尝试附加从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是否已“完成”?

1 个答案:

答案 0 :(得分:1)

尝试实施完成方法并进行检查。一个例子是,

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了解详情。

相关问题