Search code examples
iphonemfmailcomposeviewcontroller

MFMailComposer sending attached image size increased


i'm using MFMailComposer to send an image.m using this code

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];

if my image size is 500kb in MFMailModalView image size shows 2MB.

images is to big.i am send image only in the same size as in my code.


Solution

  • 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];
    

    The function will help you to compress the image in size.