0

Is it possible to reduce the image size without changing dimension of image.Similar like photoshop does.

e.g If Actual image size 400Kb with dimension 400 X 300 and if I edit & save image has low resolution. Then the image size while be 250kb with dimension 400 X 300.

Note: I need to achieve transparency if image contains. I need to push this image server and the same image while be shown in website.

Anand
  • 2,086
  • 2
  • 26
  • 44
  • 1
    See this: http://stackoverflow.com/questions/9506871/image-compression-by-size-iphone-sdk – Adam May 25 '12 at 10:49
  • @Adam thanks for your fast response. If I compress iamge into JPEG transparency part will become white right... – Anand May 25 '12 at 11:06
  • 1
    Take a look at this http://stackoverflow.com/questions/1282830/uiimagepickercontroller-uiimage-memory-and-more – Parag Bafna May 25 '12 at 11:21

3 Answers3

4

yeah it is possible .... see this code

UIImage *image = [UIImage imageNamed:@"anyImage.png"];

NSData *data = UIImageJPEGRepresentation(image, 0.5);
// 0.5 is float value it is 1.0 for same resolution

UIImage *newImage = [UIImage imageWithData:data];

Thank You!

TheTiger
  • 13,264
  • 3
  • 57
  • 82
2

gif or png images cannot be compressed. They implement a build in compression algorithm and that's it.

The best solution in your case would be to save the png image as a jpeg with a solid color replacing the transparent color, then compress the jpeg image and save it.

When you'll need the image, you will convert the jpeg image to a transparent image, by using the CGImageCreateWithMaskingColors core graphics function.

See this thread on how to make a color to transparent with core graphics

Community
  • 1
  • 1
Lefteris
  • 14,550
  • 2
  • 56
  • 95
1

It may be worth taking a look at this. This is for jpegs, it really works, and the pictures look pretty much the same. http://www.jpegmini.com/main/home

riseagainst
  • 430
  • 2
  • 6
  • 22