iOS: how to reduce size of large PNG files - objective-c

I'm currently optimizing my iOS app for the new iPad. Unfortunately by adding launch images for the iPad retina display the size of my ipa grows from 1.2MB to 5.5MB, mainly because of the two PNG images in 1536 x 2008 (portrait) and 2048 x 1496 (landscape). The size of these images are respectivly 1.9MB and 1.7MB.
The portrait can be seen here: http://uploads.demaweb.dk/iPadPortrait.png.
As you may notice, the background is a fixed pattern but sadly it seems that this is not very compressible. I've further tried to compress the images using ImageOptim, but it does not make any difference after Xcode has compressed the images during the archive. Searching the web I've noticed, that some people are dissuading to turn off PNG compressing in Xcode.
Are there anything I can do? It is not a solution to change the pattern in the image to a solid color, as it should look like the background in my iOS view. But it seems odd, that supporting the new iPad increase the size by ~4MB.

I was able to get it down to 633KB with pngquant (64 colors with slight dithering, which is barely noticeable on regular screen, and should be absolutely invisible at Retina resolution) and ImageOptim.
Yes, you will need to disable Xcode's conversion to avoid Xcode inflating files by converting them to ARGB.
NB: the article quoted in the accepted answer provides no benchmarks at all for the claimed speed difference.
It also contains correction that it is possible to optimize images with ImageOptim for iOS apps.

I'm using a great tool called ImageOptim
It incorporates a number of tools inside which crush your png files significantly (in my case it was between 25% to 50%).
One thing to remember is to disable Xcode's PNG optimization (as explained on the website)
EDIT:
Simply drag the images to the imageOptim window and the optimization will start automatically

Ive struggled with this too, unfortunately not much can be done.
In an effort to dramatically increase drawing performance of iOS apps,
Xcode re-compresses PNG files as it builds. It premultiplies the alpha
channel and byte swaps the red, green and blue channels to be
sequenced blue, green and red. The result is optimised for iOS’s
purpose, but as a side effect, ImageOptim’s work gets undone…
Source

Related

How to get crisp image for search result suggestion in Windows 8?

I'm using a 40 x 40 sized image as a search result suggestion image in Windows 8 search. Only advice about the image format I can find is to have correct size for it (http://msdn.microsoft.com/en-us/library/windows/apps/Hh700542.aspx: "Windows will scale or crop smaller or larger images").
However, the correctly sized image blurs annoyingly. The same thing happens whether I use jpg or png. Original image looks fine, but the result suggestion in the search charm is very ugly, being still of same size! Is Windows converting the image somehow, and how could I get the image to stay crisp?
I haven't noticed blurring with photo-like images, but this image contains clear lines and areas which are vulnerable to any scaling etc.
Update Sep 24:
Here is the test image I used when trying to figure out the problem. I also created different scale versions, but in my case the 100% version was used (that's why the "100" marking) - as I supposed because the resulting image really is 40x40. As you can see, the resulting image (right) is of same size as original (left), but blurry.
it does not happen that often but it seems the right solution in this case was simply to wait ;) I haven't done anything new regarding result suggestion images in my solution and today I realized that the images became crisp. Probably fixed by any of the windows updates.
[Took a stab at answering what seems the related question mentioned in the comments, so I'm posting here as well.]
It sounds like this could be related to automatic scaling of the images. Windows will automatically scale up/down based on pixel density, and you can help things scale well by either using vector-based images or, for bitmap images, supplying scale-specific versions.
For example, to scale an image referenced in markup as "AppLogo.jpg", you'd include these images:
AppLogo.scale-100.jpg
AppLogo.scale-140.jpg
AppLogo.scale-180.jpg
You can also use folders, e.g. "\scale-140\AppLogo.jpg".
For search result images, the 100% image is the 40x40 pixel version, 140 is 56x56, and 180 is 72x72. Just reference the image as "AppLogo.jpg" and the appropriate version will be used automatically. (You can also detect scale with DisplayProperties.ResolutionScale and manually choose an image.)
Here's a couple of articles with more examples/details:
"Guidelines for scaling to pixel density"
"Quickstart: Using file or image resources"
There's also some scaling discussion in the forums (general, not specific to search) here and here.

Can iPad2 use images of resolution 2048 x 1536 with no aesthetic problems?

I am developing an iOS application for iPad. Currently I am using images of resolution 2048×1536 px (iPad3 resolution). If I run this app on iPad2 or iPad1 will it get fitted to its resolution (1024×768 px)? Or should I use a 1024×768 images and specify image#2x for iPad3?
Since I only have iPad3 , cannot know how the images will be seen in the lower resolution devices. But it should work perfectly on them too.
Any help greatly appreciated. Please cite your sources.
You could try this in the simulator if you don't have a non-retina device.
It's certainly possible and will usually look fine (at least for photos, text and icons may look worse when scaled down), but you are wasting quite a lot of memory which is pretty scarce on an iPad 1 (it only has 256 MB), so you should usually also include non-retina images.
Automatically scaling down images typically results in visual artifacts, which is why the SDK includes an easy way to include different versions of any image, instead of just a single big one.
As far as I know, all iOS devices (within the same family) have resolutions that are multiples of each other so automatic scaling artifacts are somewhat mitigated, but it is still best to include the correct resolution.

Compressing huge png file to use in iphone game

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!
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.
PVRTC on Wikipedia
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.
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.
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.

Managing resources in a universal ios app

I am developing a cocos2d game. I need to make it universal. Problem is that I want to use minimun amount of images to keep the universal binary as small as possible. Is there any possibility that I can use same images I am using for iphone, retina and iPad somehow? If yes, how can I do that? What image size and quality should it be? Any suggestion?
Thanks and Best regards
As for suggestions: provide HD resolution images for Retina devices and iPad, provide SD resolution images for non-Retina devices. Don't think about an all-in-one solution - there isn't one that's acceptable.
Don't upscale SD images to HD resolution on Retina devices or iPad. It won't look any better.
Don't downscale HD images for non-Retina devices. Your textures will still use 4x the memory on devices that have half or even a quarter of the memory available. In addition, downscaling images is bad for performance because it has to be done by the CPU on older devices. While you could downscale the image and save the downscaled texture, it adds a lot more complexity to your code and will increase the loading time.
There's not a single right answer to this question. One way to do it is to create images that are larger than you need and then scale them down. If the images don't have a lot of fine detail, that should work pretty well. As an example, this is the reason that you submit a 512x512 pixel image of your app icon along with your app to the App Store. Apple never displays the image at that size, but uses it to create a variety of smaller sizes for display in the App Store.
Another approach is to use vector images, which you can draw perfectly at any size that you need. Unfortunately, the only vector format that I can think of that's supported in iOS is PDF.

Using vectors in iOS

I'm working on a simple iOS game that's always drawing 5 to 10 layers of 32bit png images which requires enough memory to crash on the ipod touch 4g when retina enabled. On other devices it works just fine. I'm not even getting memory warnings. So I was trying with lower quality images, like RGB5_A1 format, but it looks really bad because I need alpha transparency and lots of gradients.
Since all the images are exports from Illustrator I was thinking that maybe i could just export a vector image and draw in on iOS. From what i was researching hardly anyone tried this and the only option I've come across was to implement a SVG parser for Quartz.
Did I miss anything?
Also I'm worried about performance, but I couldn't find any benchmarks.
Without knowing specifics of your game, I'm going to make a few assumptions based on normal use...
You are not going to want to use straight vector graphics for this. Stick with your raster graphics.
If you are talking about 32 bit color space for your PNG images, then you need to scale back. iOS uses 24 bit images and that includes 8 bits each for red, green, blue, and alpha. As it stands, you have an extra byte for every pixel shown.
If you are using Adobe products, import the Illustrator file into Photoshop and use the "Save for Web..." option. Choose PNG-24 and you'll be all set.