iOS将UIImageJPEGRepresentation写入png格式

时间:2015-03-23 03:52:44

标签: ios uiimage

我使用UIImageJPEGRepresentation获取NSData,但文件扩展名为.png

e.g。

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

虽然我不确定我得到了什么,但它确实奏效了。我的意思是最终文件仍然是.png文件?如果我使用UIImagePNGRepresentation它会有所作为吗?干杯!

1 个答案:

答案 0 :(得分:2)

如果您使用UIImageJPEGRepresentation,则会以JPEG格式写入数据。

使用UIImagePNGRepresentation将以PNG格式写入数据。

您指定的扩展程序仅影响用户可能打开文件的应用程序。没有充分的理由将JPEG数据写入扩展名为.png的文件。