如果我們使用UIImagePNGRepresentation轉換JPEG文件,則新文件大小更多。 如果我們使用UIImagePNGRepresentation轉換PNG文件,那麼新文件的大小就會小一些。UIImagePNGRepresentation增加輸出文件大小而不是減小大小
爲什麼在這裏將JPEG轉換爲PNG更昂貴?
感謝Jithen
如果我們使用UIImagePNGRepresentation轉換JPEG文件,則新文件大小更多。 如果我們使用UIImagePNGRepresentation轉換PNG文件,那麼新文件的大小就會小一些。UIImagePNGRepresentation增加輸出文件大小而不是減小大小
爲什麼在這裏將JPEG轉換爲PNG更昂貴?
感謝Jithen
縮小圖像尺寸ü可以使用下面的代碼
CGFloat compression = 222.0f;
CGFloat maxCompression = 202.1f;
int maxFileSize = 160*165; //fill your size need
NSData *imageDat = UIImageJPEGRepresentation(image.image, compression);
while ([imageDat length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1222;
imageDat = UIImageJPEGRepresentation(decodedimage.image, compression);
}
NSLog(@"image compressed success");
[image setImage:[UIImage imageWithData:imageDat]];//image is my UIImageview
跳這有助於!
你正在加載一個PNG,然後將它保存爲PNG。這是你的意圖嗎?你看到的文件大小有什麼不同? – 2013-03-11 12:00:43
是的。加載一個PNG並將其保存爲一個新的PNG。但新的PNG文件大小超過了原始PNG文件。原來的一個是155 kb,新文件大約是266 kb .. – Coder 2013-03-11 12:10:35
http://stackoverflow.com/questions/14411369/when-i-am-using-uiimagepngrepresentation-or-uiimagejpegrepresentation-for-conver – Rushabh 2013-03-11 12:22:06