How to compress an image in iOS with objective-c - objective-c

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?

Related

How to decompress the image in react native

I want to compress the image before saving it in database add decompress the image before displaying. I compress the image using 'react-native-image-resizer' and i got base64.
How can i decompress the image to get the original quality image?

Are there any libraries for use with react native and expo that can compress an image to a target file size?

I'm building an app with react native and expo (managed). I'm trying to compress images to a specific file size but can only find libraries that allow me to set a "quality" setting (which compresses images to some arbitrary size).
Are there any libraries like browser-image-compression that allow me to set a "target" image size, for use with react native and expo?
(Or is there some other way I might accomplish this?)
The size of the image depend of many factors like level of compression, amount of details, number of colours in the image, algorithm of compression. So there is no way directly to define the image size and compress it. What you can do is to define level of compression somewhere in the middle do test compression, check if the size is above or below defined value and change accordingly the level of compression. And try again until you get desired size.

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.

Why does UIImageView load JPEGs faster than PNGs?

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.

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.