How to convert jpg images to png images from server [duplicate] - ios

This question already has answers here:
How to convert all image format into .png format?
(2 answers)
Closed 8 years ago.
Hi can anyone help in converting jpg images fetching from server into png images in objective-c.
Actually the problem is through the app,we are sharing images on facebook,but when jpg image is uploading in server,the image is not shared in facebook.
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageurl]]];
I have to convert the imageurl to png format.

Please try below code:
UIImage *img; // Your image coming from server
NSData *pngData = UIImagePNGRepresentation(img); // Convert it in to PNG data
UIImage *pngImage = [UIImage imageWithData:pngData]; // Result image

after you retrieve your images/url save them this way:
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
Answer taken from here

Related

How do i save an image in core data then retrieve it? Using swift

I don't want to use NSUserDefaults, so how do I save an image in core data then retrieve it?
My image is in this variable.
var image:UIIMage = image1
Can you please give me some sample code to do this?
UIImage -> NSData
NSData *imageData = UIImagePNGRepresentation(image); or UIImageJpegRepresentation(image)
NSData -> UIImage
UIImage *image=[UIImage imageWithData:data];
Convert UIImage into NSData and save as the entity's attribute with the type Binary Data
this question is already answered by stack-overflow refer this
How to store an image in core data

Get thumbnail from ALAssetsRepresentation as NSData

I am writing NSData to a file and saving it in the device's app documents folder. For that, is it possible to get thumbnail from ALAssetsRepresentation object in NSData format. If so, any helpful links to that?
I couldn't find anything similar, other than getting CGImageRef from ALAssetsRepresentation. I don't want CGImageRef format as I have to use UIImageJPEGRepresentation or UIImagePNGRepresentation to convert it to NSData.
Try this one
GImageRef iref = [myasset thumbnail];
if (iref)
{
UIImage *theThumbnail = [UIImage imageWithCGImage:iref];
NSData *thumnailData = UIImagePNGRepresentation(theThumbnail);
}

Can't display BLOB image in iOS application

I'm trying to display a BLOB image (get from web server using Json) in my iOS app, but when I run my application I get an empty UIimageView, here is my code :
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:encodedUrl]];
NSData *profileImage1 = [[NSData alloc] initWithBytes:[dataURL bytes] length:[dataURL length]];
UIImage *profileImage2 = [UIImage imageWithData:profileImage1];
[profilImage setImage:profileImage2];
How can I fix this problem?
[UIImage imageWithData:data] only parses known image file formats like JPEG, PNG, etc. (Full info in the decomentation). Passing blobs isn't supported by UIImage. You need to do some decoding to be able to use the data for the UIImage. You can use GMTBase.64 for encoding and decoding of data. Read the docs and other posts and you'll find out how to change your code.
Hope this helps.

iOS: writing a CGImageRef disk in png or jpeg

What is the best way to save CGImageRef to a png or jpeg file in iOS?
For a general cocoa application (not using UIkit), see: Saving CGImageRef to a png file? but this seems too long and clunky.
Using UIKit, the code becomes a simple 3-liner:
UIImage *uiImage = [UIImage imageWithCGImage:cgImage];
NSData *jpgData = UIImageJPEGRepresentation(uiImage, 0.9f);
[jpgData writeToFile:path atomically:NO];

Send UIImage to server

I want to send UIImage from my application to the server. I use ASIHTTPRequest. I'll send NSData but how to convert from UIImage to NSData?
If you need PNG data in your NSData you can use:
NSData *data = UIImagePNGRepresentation(img);
Where img is your UIImage. There is a similar function for JPG.
The UIKit functions UIImageJPEGRepresentation() and UIImagePNGRepresentation() should do what you want.

Resources