JohnnL
JohnnL

Reputation: 111

iOS write UIImageJPEGRepresentation to png format

I used UIImageJPEGRepresentation to get the NSData but the file extension is .png.

e.g.

NSData *imageData = UIImageJPEGRepresentation(anImage, compression);
[imageData writeToFile:@"abc.png" atomically:YES];

It worked, although I am not sure what I am getting. I mean is the final file still a .png file? If I use UIImagePNGRepresentation would it make a difference? Cheers!

Upvotes: 2

Views: 985

Answers (1)

Aaron Brager
Aaron Brager

Reputation: 66234

If you use UIImageJPEGRepresentation, you'll write the data in JPEG format.

Using UIImagePNGRepresentation will write the data in PNG format.

The extension you specify only affects what applications a user might open the file in. There's no good reason to write JPEG data to a file with a .png extension.

Upvotes: 2

Related Questions