1

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.

Thanks Jithen

Coder
  • 1,661
  • 4
  • 27
  • 50

2 Answers2

3

There is nothing in iOS SDK to give you image size in inches from given pixel, one option is to determine on which device your app is running and then calculate size in inches for you image object.

Community
  • 1
  • 1
Ankur
  • 5,086
  • 19
  • 37
  • 62
  • will it give correct resolution for any Image ??? I mean leave what device we're using I just want to know the resolution of any image it may be downloaded from google ? – TheTiger Mar 11 '13 at 12:04
  • @TheTiger: you must check for device because different iOS devices has different pixel ratios, you can't just leave device while calculating pixels to inches. If apple launches new device in future, you should add validation/check for that device too. – Ankur Mar 11 '13 at 12:19
  • No no ...... I'm asking If image is not taken by device camera. And I'm not showing it in any UIImageView or UIIView then it will calculate correct DPI for UIImage .... take UIImage as raw material there is no User Interface .... – TheTiger Mar 11 '13 at 12:28
2

You can get the size in points by image.size.width and image.size.height...

To get the value in pixels, multiply those by image.scale. To get the size in inches, you can maybe multiply them by 1/264.0 instead (according to Wikipedia)...

jjv360
  • 4,120
  • 3
  • 23
  • 37
  • will it give correct resolution for any Image ??? I mean leave what device we're using I just want to know the resolution of any image it may be downloaded from google ? – TheTiger Mar 11 '13 at 12:05
  • Images can't accurately be converted to a size other than pixels, since every display has a different pixel density, etc... You should really look at the amount of pixels when compressing, since with a lot of image formats it can set it's PPI to almost anything, which changes the (printed) image size but doesn't affect the file size at all... – jjv360 Mar 11 '13 at 12:26
  • I'm not showing it in any UIImageView or UIIView then it will calculate correct DPI for UIImage .... take UIImage as raw material there is no User Interface .... Then we cant find image resolution ? – TheTiger Mar 11 '13 at 12:36
  • Normally on computers the DPI or PPI etc is pretty much meaningless, only pixels actually mean something... – jjv360 Mar 11 '13 at 12:38