1

I've googled a lot about this question, but couldn't find anything interesting for me.

Q: Is there any class or method to change image quality(not size or scale, but the quality keeping the same size and scale).

As I understand there is no native(default) classes or methods to do this, am I right?

Any help would be appreciated.

Garnik
  • 423
  • 1
  • 6
  • 20
  • Why would you want to do this? ON what images do you intend to do it? – David Rönnqvist Jul 24 '12 at 15:03
  • [possible dupe](http://stackoverflow.com/questions/487316/reduce-uiimage-size-to-a-manageable-size-reduce-bytes) – Dima Jul 24 '12 at 15:04
  • It depends on the image format. A JPEG, i.e., can encode an image with different compression rates. – The dude Jul 24 '12 at 15:04
  • @Dima this is not dupe, because I want completely different thing. I don't want to store thumbnails or resize image. I need to send image with exactly the same size(dimensions) and scale, but I'm allowed to change quality in order to lessen the size(in MB) – Garnik Jul 24 '12 at 15:19
  • @DavidRönnqvist I want to send these images via POST to server which is already working with images from other apps, so I'm not allowed to change anything in server configurations or server side app. I want to do it with PNG files. – Garnik Jul 24 '12 at 15:20

2 Answers2

2

If you have an image as a UIImage, you can use the UIImageJPEGRepresentation function, specifying a compression quality,to create an NSData object. This data object can then be used to create a new UIImage.

See the Apple Docs

Ian L
  • 5,553
  • 1
  • 22
  • 37
  • Sorry that's my fault, forgot to tell I can't use JPG, because I have transparent pixels in my .png image, which I can have only if my image is PNG format, because JPG set transparent pixel to white. Transparent pixels are those pixels which red=0 green=0 blue=0 alpha=0. – Garnik Jul 24 '12 at 15:30
0

This functionality is already available in iOS SDK itself to set image quality. In the UIImage class, there is one method UIImageJPEGRepresentation.

In this function pass your image and image compression quality. It will not change dimension of the image but it will change the dip of the image to maintain the quality. It will help to maintain the size in memory as well.

NSData * UIImageJPEGRepresentation (
   UIImage *image,
   CGFloat compressionQuality
);

Parameters:

 - image : The original image data.
 - compressionQuality: The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).

Hope this is what you required.

Enjoy Coding :)

Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • check this out: http://www.iphonedevsdk.com/forum/iphone-sdk-development/5204-resize-image-high-quality.html in that code added by PhoneyDeveloper. – Mrunal Jul 24 '12 at 15:54