MFMailComposer发送附加图像大小增加

时间:2012-03-22 14:04:25

标签: iphone mfmailcomposeviewcontroller

我正在使用MFMailComposer使用此代码发送image.m

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        if (picker !=nil) {
            picker.mailComposeDelegate = self;
            NSString *msgTitle;
            [picker setToRecipients:[NSArray arrayWithObjects:@"", nil]];
            [picker setSubject:msgTitle];
            [picker addAttachmentData:UIImagePNGRepresentation(imageView.image) mimeType:@"image/png" fileName:@"img"];
            [self presentModalViewController:picker animated:YES];

如果我的图像尺寸为500kb,则MFMailModalView图像尺寸显示为2MB。

图片是big.i我发送图像的大小与我的代码相同。

1 个答案:

答案 0 :(得分:1)

NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality)

//Replace this snippet to your code
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
if (picker !=nil) { 
   picker.mailComposeDelegate = self; 
   NSString *msgTitle;
   [picker setToRecipients:[NSArray arrayWithObjects:@"", nil]]; 
   [picker setSubject:msgTitle];    
   [picker addAttachmentData:UIImageJPEGRepresentation(imageView.image,0.5) mimeType:@"image/png" fileName:@"img"]; 
   [self presentModalViewController:picker animated:YES];

该功能可帮助您压缩图像大小。