Why does UIImageView load JPEGs faster than PNGs? - objective-c

I've realized that UIImageView loads JPEG images faster than PNG files. Or, at least it renders images faster, for example using its startAnimating method.
1. How fast jpg files loaded than png files.
2. And my main question is, Why? Does PNG images have complex structure?!
I have tested this with a collection of JPEGs and another collection of PNGs. Almost all have the same file size.

Related

Combining two resized (matched sizes) images together with image magick

I have two images I want to combine together with image magick. The way I have it setup right now is a form will upload an image to a server, resize the image to make a smaller version, then save both to a folder. I have my code setup correctly for this using image magick and it works just fine.
What I'm looking to accomplish is sort of like annotating it, however I'd like to do this by appending a header image to the top of the file. I know I can accomplish this using the -append flag. What I'm confused on is how I can match the image sizes so I don't need to do several resizes.
I'm making the resizing occur only if the uploaded files exceed 1000x1000 (using the -resize 1000x1000> argument), but this doesn't guarantee that all files will be 1000px wide. I've made the header image 1000 pixels wide, and when the image is at 1000px, appending those is no problem.
My problem is deciphering how it should be handled when it's smaller than that. Do I resize the header image to the other images size, then append? I know it'd be better to avoid scaling the image up to 1000px, then appending the header and scaling back down, as that would affect image quality. Can I resize the header image without writing it to a temporary file? Like, chain the events and only end up writing a single completed file to disk?

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.

Ideal image size and format

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/

About animating frame by frame with sprite files

I used to animate my CCSprites by iterating through 30 image files (rather big ones) and on each file I changed the CCSprite's texture to that image file.
Someone told me that was not efficient and I should use spritesheets instead. But, can I ask why is this not efficient exactly?
There are two parts to this question:
Memory.
OpenGL ES requires textures to have width and height's to the power of 2 eg 64x128, 256x1024, 512x512 etc. If the images don't comply, Cocos2D will automatically resize your image to fit the dimensions by adding in extra transparent space. With successive images being loaded in, you are constantly wasting more and more space. By using a sprite sheet, you already have all the images tightly packed in to reduce wastage.
Speed. Related to above, it takes time to load an image and resize it. By only calling the 'load' once, you speed the entire process up.

What is the optimal image format for display in a UIImageView control?

I have images on a server that will be downloaded and displayed in a UIImageView control. What is the optimal image format for these images, .jpg, .png, etc? I want to minimize the d/l time and also have the best quality images displayed.
PNG is pretty much the standard. They're already zipped and are lossless.