上传图片问题(UIImageJPEGRepresentation vs UIImagePNGRepresentation) [英] Uploading image issue (UIImageJPEGRepresentation vs UIImagePNGRepresentation)

查看:199
本文介绍了上传图片问题(UIImageJPEGRepresentation vs UIImagePNGRepresentation)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Safari的保持+保存图片选项存储了一些图片到我的照片库在模拟器。当我从库中选择一个图像,我必须将其转换为JPEG或PNG,所以我可以将其上传到服务器。问题是原始图像的大小约为200 KB,但转换为PNG后的图像大约为2 MB。我使用 UIImagePNGRepresentation UIImage 对象转换为 NSData 然后张贴图像。

I have stored a few pictures using Safari's "Hold + Save Image" option to my Photo Library in simulator. When I pick an image from the library, I have to convert it to JPEG or PNG so I can upload it to the server. Issue is that the size of original image is around 200 KB but the image after converting to PNG is around 2 MB. I'm using UIImagePNGRepresentation to convert UIImage object to NSData and then posting the image.


  1. 我在这里缺少什么?为什么图片的大小比原始大小大?

  1. What am I missing here? Why is the size of picture getting larger than its original size? How can I prevent this?

UIImageJPEGRepresentation UIImagePNGRepresentation之间有什么区别

我可以确定从照片库加载的图片类型吗?

Can I determine the type of image loaded from photo library?

iPhone相机捕获的图片的默认类型是什么?

What is the default type of images captured by the iPhone camera?


推荐答案

我想猜测原始图片是以JPEG格式储存的。

I'm guessing that the original image is stored as a JPEG.

PNG专为储存萤幕画面和线条绘图等而设计。它不是为存储照片等内容而设计的。

PNG is designed for storing things like screen shots and line drawing. It is not designed for storing things like photos.

这一切都归结于所使用的压缩类型,PNG使用无损压缩,以使图像完全相同原始图像。 JPEG使用有损压缩,生成的图像是对原始图像的近似。

It all comes down to the type of compression used, PNG uses lossless compression so that the image will be exactly the same as the original image. JPEG uses lossy compression, the resulting image is an approximation to the original.

如果您拍摄有损JPEG,然后将其另存为PNG,

If you take a lossy JPEG and then save it as a PNG then it will increase in size, often by a large amount as you have seen.

您的问题的解决方案是在您上传图片之前不对图片进行任何操作。它们已经是PNG,GIF或JPEG图像。

The solution to your problem is to do nothing to your images before you upload them. They will already be PNG, GIF or JPEG images. That is what you should upload.

iPhone相机保存的图片格式为JPEG。

The format of the images saved by the iPhone camera is JPEG.

听起来像你可能需要在 PNG JPEG

Sound like you probably need to do some reading up on PNG and JPEG generally.

这篇关于上传图片问题(UIImageJPEGRepresentation vs UIImagePNGRepresentation)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆