I have a background file that I wish to use in an iphone game which is currently 40mb. It is a .png file and I would like to compress it to the smallest size possible without losing much quality AND without losing the alpha channel. I have successfully changed the file size of a similarly large file simply by changing its file type to a .jpg file. However, this image didn't have any transparency, and as far as I know you cannot change a .png to a .jpg without losing transparency. Perhaps I am wrong however(and please correct me if I am.) If there is a way to compress this .png file please explain to me how it is done. Also, please be aware that it is quite a large file and it would be preferable that it compressed within a time range of 5 hours or below if possible. Thanks!
-
Try to use this app - http://www.irfanview.com/ you can set compression level while saving. It also have batch conversion mode - so you can recompress whole your images with 2-3 clicks. – k06a Apr 23 '12 at 07:21
-
Why don't you try [PNG Squeezer](http://itunes.apple.com/us/app/png-squeezer/id467969231?mt=12) ? – Dr.Kameleon Apr 23 '12 at 07:25
-
When a PNG is decompressed, it occupies at least as much memory as its compressed form took on disk - possibly much more. If you have RGB and alpha, it will need 4 bytes per pixel after decompressing. Earlier iOS devices will run out of memory while trying to load just one image this big. Can your background image be broken into independent tiles? – Cowirrie Apr 23 '12 at 07:29
-
thanks for the suggestions guys, and it would be preferable to use just one image, but I may have to break it into tiles if worst comes to worse – Fitzy Apr 23 '12 at 07:32
3 Answers
How are you building the game? If you're using OpenGL directly, and if you're happy with the compression it offers, PVR is an awesome format for far smaller and really quick images.
As keegan3d said, Xcode recompresses PNG images, using PNGCrush. It changes the byte order and premultiples the alpha. This article explains what happens: iPhone "Optimized" PNGs
If you leave Xcode's PNG compression enabled, then you won't see any benefits from using PNG compression tools: PNG compression and iOS apps
If you'd like to disable Xcode's compression for one image only (so you can use an alternate compression tool), I believe you can change the file type from image.png
to file
, as explained here: How can I skip compressing one PNG?
And... be a little careful with RAM usage. A JPEG and PNG will both decompress to the same size (assuming they have no alpha). 40MB is quite big. Do you have other ways of drawing the background? I've worked on a game with a bitmap 2048 x 2048 play area that was bitmap based. We use PVR and tiles. PVR images use less RAM than PNG, and are quicker.

- 1
- 1

- 1,318
- 10
- 12
Xcode compresses pngs, you should look at how large the image actually is inside the built app. It is possible to compress images more than Xcode does with ImageOptim but they are slightly slower to display on screen, this probably wouldn't be an issue for your background image.

- 10,357
- 9
- 53
- 77
-
Thanks, I didn't realize Xcode compresses them already. That helps alot. – Fitzy Apr 23 '12 at 09:03
-
Yes they are compressed an optimized for faster loading on the GPU. ImageOptim can compress them more but in my testing it was slower to get them on the gpu but only noticeable if you are playing an image sequence. – keegan3d Apr 23 '12 at 19:25
In my benchmark smallest size and fastest loading PNG images were PNG8+alpha created with ImageAlpha/pngquant.
If your background is mostly flat or monochromatic (not too much blur/gradients), then it will look fine as PNG8+alpha.
You can improve compressibility of PNG24+alpha images by posterizing them in a smart way.
However, a 40MB PNG image is still huge. I wouldn't be surprised if it was causing you memory issues. Consider splitting it into smaller tiles.

- 97,764
- 37
- 219
- 309