Given that I have a UIImage that is stored in a local variable:
UIImage *myImage = (Some image extracted somewhere)
How do I add this image as an attachment through MFMailComposeViewController ?
The image isn't stored on the users device and it's simply available at runtime.
So I can't access this image through a file name as other questions/examples have demonstrated.
Thank you!
NSData *imageData = UIImageJPEGRepresentation(photo, 0.9);
NSString *attachmentName = #"Any name.jpg"
[mailer addAttachmentData:imageData mimeType:#"image/jpeg" fileName:attachmentName];
Related
I'm making a photo gallery app.
I'm compressing the images
NSData *imageData = UIImageJPEGRepresentation(image,0.5)
and then want to create a duplicate (for thumbnails) that I'll compress even further
NSData *imageData = UIImageJPEGRepresentation(image,0.2)
I'm a little stuck on the middle step of how to create a duplicate, anyone know if there is a function for this?
Probably you can convert NSData to UIImage.
Swift3:
let imageData = UIImageJPEGRepresentation(thumbImage,0.5)
let thumbImage = UIImage(data:UIImageJPEGRepresentation(UIImage(data: imageData),0.2))
Objective C:
NSData *imageData = UIImageJPEGRepresentation(image,0.5)
UIImage *thumb = [UIImage imageWithData: UIImageJPEGRepresentation([UIImage imageWithData: imageData],0.5)];
I Get this kind of JSON:
NOTE: I put dots in "content" because it is too long byte array abd just to explain the situation.
{
"id":"53abc6a7975a9c10c292f670",
"nfcId":"testse",
"company":"TESt",
"qrId":"testvalue",
"address":"ajs;ldfh",
"mimeType":"IMAGE",
"url":"",
"content":"iVBORw0KGgoAAAANSUhEUgAA....."
}
And im trying to get this Json and diplay this information
the "content" field has a Byte array converted on the server from Image to byte array.
I use this code in xCode to convert those bytes to NSData, then to UIImage to be able to display it in UIImageView:
NSData *dataImage = [jsonArray[key] dataUsingEncoding:NSUTF8StringEncoding];
NSLog(#"data = %#", dataImage);
UIImage *img = [UIImage imageWithData:dataImage];
NSLog(#"img = %#", img);
The image is always gives me null.Although, data give me array of data.
I tried all kinds of encodings as a NSData parameters also:
dataUsingEncoding:NSASCIIStringEncoding
dataUsingEncoding:NSUTF8StringEncoding
dataUsingEncoding:NSUTF16StringEncoding
dataUsingEncoding:NSUTF32StringEncoding
I've used code like this before
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"data:image/png;base64,%#",jsonArray[key]]];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *img = [UIImage imageWithData:imageData];
Note that initWithBase64EncodedString is only available from iOS7 onwards
I tried this code just right now and it works:
NSData* dataImage = [[NSData alloc] initWithBase64EncodedString:jsonArray[key] options:0];
UIImage *img = [UIImage imageWithData:dataImage];
The "content" encoded by Base64 String type.
I'm successfully sending an email with attached UIImage from my app, but is it possible to attach more than one image with MFMailComposeViewController ?
you can save all the images in an NSMutable array and run the code
[mailer addAttachmentData:imageData mimeType:#"image/png" fileName:#""];
for the count of your NSMutableArray. It will add the images to attachment field
for (int i = 0; i < [_textField0.emojiArray count]; i++)
{
emoji = [_textField0.emojiArray objectAtIndex:i];
UIImage *image = [EmojiResizer resizeImage2:[UIImage imageNamed:emoji.screenfilename]
imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
[mailViewController addAttachmentData:imageData mimeType:#"image/png" fileName:emoji.filename];
}
Do something like this.
Call addAttachment... for each attachment you wish to add.
My App sends an e-mail with images but there is no images in the e-mail.
I create a HTML string and send that as the body in the e-mail. But there is nothing in the e-mail when doing it on the device.
In the simulator is okay.
I put a WebView in my App and put the HTML in and its shows all the images.
Anyone know what could be the issue?
This is code I used to attach image in mail body
NSMutableString *htmlBody = [[NSMutableString alloc] initWithString:#"<html><body>"];
[htmlBody appendString:#"<p>Enter Text Here</p>"];
UIImage *emailImage = [UIImage imageNamed:#"image.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
NSString *base64String = [imageData base64EncodedString];
[htmlBody appendString:[NSString stringWithFormat:#"<p><b><img src='data:image/png;base64,%#'> </b></p>",base64String]];
[htmlBody appendString:#"</body></html>"];
NSLog(#"%#",htmlBody);
[mailComposer htmlBody isHTML:YES];
Hope it helps you..
As you can see, that I have put my the national flags in a folder in Xcode and I am trying to display it to the navigation bar. However, it is not showing up and I found out:
NSString *imageName = [NSString stringWithFormat:#"%#.icns",countryName];
UIImage *image = [UIImage imageWithContentsOfFile:imageName];
image is "nil".
Any idea? Thanks!
You could use like this
NSString *imageName = [NSString stringWithFormat:#"%#.icns",countryName];
UIImage *image = [UIImage imageNamed:imageName];
Please Try This
Check whether the file actually exists. I suspect it doesn't. Use [NSFileManager defaultManager] fileExistsAtPath:.
Where was the image path you are sending NSString to here
UIImage imageWithContentsOfFile:imageName
send the path to that method. or make like this
UIImage *image = [UIImage imageNamed:[NSString stringwithFormat:#"%#.icns",countryName]];