Converting UIImage to NSString to embedded image in email body from iphone app

December 29, 2009 § 3 Comments

Including image within email body from iphone app is a very tricky business. Using Base64 encoding according to my search results works on all mail server except Gmail. Gmail won’t allow embedded images.
These are the Objective-C methods converting from UIView to NSString for email body.
  • Converting the UIView to a UIImage using UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  • Converting the UIImage to NSData using NSData *imageData = UIImagePNGRepresentation(viewImage);
  • Convert the NSData to Base64
  • Converting the Base64 encoded image data into an NSString using NSString *dataStr = [NSString stringWithCString:encodeArray length:strlen(encodeArray)];
  • Embedding the image into email using NSString *body       = [@"" stringByAppendingFormat:@"<b><img src='data:image/png;base64,%@' alt='Interpolate Chart'></b>", dataStr];
  • <b> and </b> in the embedded image code above must be present, or mail will strip your image.
Advertisements

§ 3 Responses to Converting UIImage to NSString to embedded image in email body from iphone app

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Converting UIImage to NSString to embedded image in email body from iphone app at Web Builders.

meta

%d bloggers like this: