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.
Related
I want to compress an image (jpeg and png).
I found this answer:
how to compress image in iphone?
But this resizes the image or take down the quality (or both).
I want something like the program 7-zip does for pc.
It takes an image and compresses it and gives it .zip as extension.
The primary goal is to take down the amount of space it uses on the disk.
It is possible to compress an image with objective-c in iOS?
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
I'm building an image gallery type of application and i want to know what is the best image size and format (.png or .jpg) to be stored in the app.
I also want to know what is the best and most efficient way to store and load images natively.
PNGs are optimized for the OS when they are added to your app bundle. To improve performance of your app you want to:
Make sure the images have no alpha channel in them, otherwise the OS will try and blend them.
Resize your images to be the size they will end up in the UI. This will reduce the read bandwidth for the drawing, saving you memory and boosting performance.
Images in the app bundle can be read into UIImageViews:
UIImageView *newImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myimage.png"]];
This will cache the image for you, which is good for lots of small images re-used a lot. For larger infrequently used images you want to use +imageFromContentsOfFile: instead of +imageNamed:
As far as I know iOS and xCode optimizes PNG formats and performs better with them.
You may want to check out this :
http://bjango.com/articles/pngcompression/
I need to take some images from the iPhone / iPad photo library from within my app and store them in a Core Data entity, and display them as small thumbnail images (48x48 pixels) in a UITableViewCell, and about 80x80 pixels in a detail UIView. I've followed the Recipes sample app, where they use UIImageJPEGRepresentation(value, 0.1) to convert to NSData and store the bytes inside Core Data, and it doesn't end up taking much space, which is good. But when retrieve the data, using UIImage *uiImage = [[UIImage alloc] initWithData:value]; and display it as a thumbnail image with "Aspect Fit", it looks terrible and grainy. I tried changing the image quality variable in the JPEG compression, but even setting it to 0.9 doesn't help.
Is that normal? Is there a better way to compress the image that doesn't cause so much grainee-ness? Since I just want to show a small thumbnail, and then a slightly bigger thumbnail, I feel Core Data would be great for storing this, since it should (theoretically) also support iCloud. But if it's going to look terrible, then I'll have to reconsider.
Two things, are you resizing the image to the right size? Have you tried UIImagePNGRepresentation()? That should compress it without losing quality.
If UIImagePNGRepresentation (which is lossless) is giving you bad images, then the problem is in your image resizing code. Core Data is just giving you what you back what you put in, so if you get bad images out, it's because you put bad images in.
Is one of your iPhone/iPad retina and the other isn't? If so, perhaps the problem is that you don't really want 48x48 pixel images, you want 48x48 point (which means you'll need 2x images 96x96 for retina quality display).
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.