简体   繁体   English

如何获取以英寸为单位的UIImage大小或UIImage分辨率?

[英]How to get UIImage size in inches or UIImage resolution?

I want to compress my image and upload to server. 我想压缩图像并上传到服务器。 This compression should be depended on the image size. 这种压缩应取决于图像大小。 Or it would help if we have any API in iPhone to get image resolution so that based on this resolution, i can set the compression rate. 或者,如果我们在iPhone中具有任何API来获取图像分辨率,也将有所帮助,以便基于此分辨率,我可以设置压缩率。

Thanks Jithen 谢谢吉森

iOS SDK中没有提供给定像素的以英寸为单位的图像大小的方法,一种选择是确定您的应用在哪个设备上运行 ,然后为图像对象计算以英寸为单位的大小

You can get the size in points by image.size.width and image.size.height ... 您可以通过image.size.widthimage.size.height获得以image.size.width为单位的大小...

To get the value in pixels, multiply those by image.scale . 要获得以像素为单位的值, image.scale乘以image.scale To get the size in inches, you can maybe multiply them by 1/264.0 instead (according to Wikipedia )... 要获得以英寸为单位的大小,您可以将它们乘以1/264.0 (根据Wikipedia )...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM