Search code examples
iphoneobjective-ccocoaios4uiimage

Reduce image file size


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.


Solution

  • 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