Ideal image size and format - objective-c

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/

Related

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.

Vector art on iOS

We've now got 4-resolutions to support and my app needs at least 6 full-screen background images to be pretty. Don't want to break the bank on megabytes of images.
I see guides online about loading PDFs as images and custom SVG libraries but no discussion of prectically.
Here's the question: considering rendering speed and file size, what is the bet way to use vector images in iOS? And in addition, are there any practical caching or other considerations one should make in real world app development?
Something to consider for simple graphics, such as the type of thing used for backgrounds, etc., is just to render them at runtime using CG.
For example, in one of our apps, instead of including the typical repeating background tile image in all the required resolutions, we instead draw it once into a CGPatternRef, then convert it to a UIColor, at which point things become simple.
We still use graphic files for complex things, but for anything that's simple in nature, we just render it at runtime and cache the result, so we get resolution independence without gobs of image files. It's also made maintenance quite a bit easier.

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.

Scaling of image (scriptable image processing system)

I want to scale images to 400x400 (I am creating thumbnails). I am using the Scriptable Image Processing System (SIPS) in a Cocoa application, but the problem is poor efficiency. SIPS takes 70-90% CPU while converting 300 images in 20 seconds. Should I use the CIImage class (CIImage is the type required to use the various GPU-optimized Core Image filters) or NSImage class? Can anyone suggest a better method?
A very simple and fast way to generate thumbnails on OS X is to use QLThumbnailImageCreate.
It's just one line of code so you can easily try out how it compares to SIPS & Core Image.
I tried thumbnail genration using NSImage , CIImage and sips. All are taking same CPU (70-90%) usage but sips is faster.

iOS: storing thumbnail images in Core Data

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).