I've been developing an Android app which takes picture and save it. And I want make the upload speed more faster by compressing the image. But as I compressed them using BitmapCompress, the image seems lost its quality. Here :
RAW :
COMPRESSED :
BEFORE :
DIMENSION - 1920X1920
FILE SIZE - 2.94MB
AFTER :
DIMENSION - 960X960
FILE SIZE - 644KB
I wonder if there's a way, a library perhaps that will solve my problem? Instagram seems to be doing this compression stuff without losing the image quality.
Compressing will always lead to decreased quality in the one or the other way.
Here is what you could do:
Change your compression format to PNG, if you are not already using that.
Find a perfect compromise for the quality value between size and quality
I agree with #Saret BitmapCompress will decrease the file size with a good quality. You can get ~800-900KB photo from ~3MB photo using 80% quality compressing without scaling. You can get better result if you crop the photo.
If you don't care scaling and details in depth are not important for you, I strongly recommend following libraries:
https://github.com/shaohui10086/AdvancedLuban
https://github.com/zetbaitsu/Compressor
Bitmap yourbitmap
[...]
OutputStream os = new FileOutputStream(filename);
yourbitmap.compress(CompressFormat.JPEG, 80, os); // 80% compression
This will keep your image light and with a good quality.
Some keywords worth looking into:
'EXIF removal' libraries
'lossless compression' libraries
Explanations:
Remove some of the excess EXIF data
You can try reducing filesize by removing the EXIF data that is stored in the image. In many cases, the EXIF data takes up a lot of room, and often contains more information than the user might need for their use case.
A quick google search shows the following tool could be helpful in removing the EXIF data. Has Windows and Mac versions:
http://www.exifpurge.com/
As for a tool that would work in your android build process, that needs further searching. But at least 'EXIF removal android library' are good keywords to start with
Lossless compression
Another alternative is researching lossless compression. I've used them in the past in web development. In my case, I used libraries which worked from the command line together with 'grunt' a build tool.
A quick google search showed the following site which works direct from your browser.
https://compressor.io/compress
Related
In my app there are 180 images in drawable folder & I will display them at the background of textview covering the entire screen.
Android documentation states that Android supports bitmap files in a three formats: .png (preferred), .jpg (acceptable), .gif (discouraged).
It also states that Bitmap files may be automatically optimized with lossless image compression by the aapt tool during the build process. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build. If you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in the res/raw/ folder instead, where they will not be optimized.
I dont want the apk size to exceed 50 MB, Can *.png images minimize the apk size as compared to other extensions(.jpg,.gif)?
As you already read in the documentation, the images are already compressed a great deal. However, you might want to try other compression tools available to reduce the size of images.
It's generally a better idea to save images as jpegs rather than pngs. As pngs are bigger in size because of the alpha channel (transparency). Not always though. So, in case you dont need transparency in images it'd be a better idea to switch to jpegs.
I generally use this : https://tinypng.com/
Better you compress the .jpg files as much as possible, this should greatly reduce the size of your .apk file. And there is a tool such as Paint.NET and refer APK too It has great resizing options.
Yes, and this is from what i know from using photoshop,
here is a very well explanation of why to use each:
PNG vs. GIF vs. JPEG vs. SVG - When best to use?
it can help you reduce the apk size... honestly i think it would be best for you to download photoshop (even the 30 day ver.) and simply load and save and see to comparison yourself.
Maybe someone else was faced with this problem:
As the title says, when uploading screenshots from devices to our server image quality degradation is quite high. You can see one example on the following link
http://cdn.voicebo.com/7507-05e6a7b3bf91d96b2d08da649c2ef590.jpg
This screenshot was taken on Nexus 4 but same thing happens on Galaxy S2, S3 and Note 2. Unfortunately we don't have more phones to test for this right now but considering popularity of following models this affect large number of our users.
I have searched for quite some time to answers or reasons why this might happen and found the following link which is not really what I was looking for but contains some information
http://www.google.rs/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCYQFjAA&url=http%3A%2F%2Fandroidforums.com%2Fsamsung-galaxy-s3%2F580114-screenshot-glitch.html&ei=1dKdUbPNA8nBO7G9gPgE&usg=AFQjCNECq7UNMp16pU8WLMlLwZVb4i2Ofw
I have also came to conclusion that screenshot images are saved as png files while images from the camera are in jpeg (I think this is same for all ROMS but might be wrong) so this might be the problem too. Part I don't get is why would this be an issue, because as I understand when you read image file from any supported format you get raw bytes of data for that image so input format shouldn't play role in output compression if raw bytes were read without errors.
Relevant part of code in image compression is only this but if more info is required I can add more:
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
Questions I am asking are:
Has anyone else faced this problem and how did you solve it?
How should I compress png images (using what settings) to get best results at reasonable file size?
Bonus:I am currently trying out a way to detect which file format the image is but if someone used this to solve similar issue please mention that in answer too.
Edit:How to get the Image Format of the images from Gallery is the part I am using now to get format of image but this doesn't actually answer the question. Thanks to all the guys there for useful discussion.
Now you've mentioned the options.inSampleSize setting, it seems incredibly likely that your problem is caused by this: setting options.inSampleSize = 4 tells the encoder to throw pixels away (apparently literally; proper resampling would look better than your example), which is exactly what you're seeing.
You need to make some decisions about what should be reduced in size and what shouldn't - you say in your comment than this setting should be determined by input bounds, so it sounds like you're already doing this and perhaps you need some debugging there.
I'd reiterate that changing PNGs to JPEGs might not be the best option, unless your screenshots often contain photographic content. As you may know, PNG is very poor at compressing photographic content, but conversely, JPEG is very poor at maintaining quality with the sorts of images commonly found on computer / device screens. PNG can often produce smaller files in such circumstances than acceptable JPEG images.
While developing an Android app what format of sound/image should i should be using so that i can control the overall size of the app after completion.
here is a link to all the media types supported by Android.
For sound I would probably use a low-bitrate .mp3 or a .midi and for images either a compressed .jpg or .gif
For supported media formats see this.
For images you'll probably end up with JPG or PNG (if you need transparency). You should also scrape the images to remove all unnecessary meta data etc. For linux, a nice tool for this is Trimage.
Take a look at Supported Media Formats.
My choice would be:
Images: go with JPG for compression or PNG for quality and transparency support.
Audio: go with MP3-VBR (variable bit rate) for compression and quality.
The size of your file will be greatly affected by compression level. At some point, if you compress too much you will see/hear artifacts. The acceptable level of compression is subjective and really depends on the input data (image or audio). You should be testing different levels of compression to see what works.
From experiments and from reading other posts like this one it seems that it's hard to process high resolution images on Android because there is a limit on how much memory the VM will allow to allocate.
Loading a 8MP camera pictures takes around 20 MB of memory.
I understand that the easy solution is to downsample the image when loading it (BitmapFactory offers such an option) but I still would like to process the image in full resolution: the camera shoots 8MP, why would I only use 4MP and reduce the quality.
Does anyone know good workarounds for that?
In a resource-constrained environment I think that your only solution is to divide and conquer: e.g. caching/tiling (as in: tiles)
Instead of loading and processing the image all at once you load/save manageable chunks of the image from a raw data file to do your processing. This is not trivial and could get really complex depending on the type of processing you want to do, but it's the only way if you don't want to comprise on image quality.
Indeed, this is hard. But in case image is in some continuous raster format, you can mmap it
( see java.nio.ByteBuffer ) - this way you get byte buffer without allocating it.
2 things:
Checkout the gallery in Honeycomb. It does this tiled based rendering. You can zoom in on an image and you see then that the current part is higher res then the other parts. If you pan around you see it rendering.
When using native code (NDK) there is not a resource limit. So you could try to load all the data native and somehow get parts of it using JNI, but I doubt it's better then the gallery of honeycom.
I am developing an app which has a lot of images to work on due to which the size of my app has become very large. I want to compress or something like that to reduce the size of app. Any idea?
.png-files which are placed in the res/drawable are automatically optimized when compiling your app:
Bitmap files may be automatically optimized with lossless image
compression by the aapt tool during the build process. For example, a
true-color PNG that does not require more than 256 colors may be
converted to an 8-bit PNG with a color palette. This will result in an
image of equal quality but which requires less memory. So be aware
that the image binaries placed in this directory can change during the
build. If you plan on reading an image as a bit stream in order to
convert it to a bitmap, put your images in the res/raw/ folder
instead, where they will not be optimized.
That being said, you have some more options to try. There is a good talk on this topic from Google I/O 2016 called "Image Compression for Android Developers", which outlines the possibilities, explains their up and downsides and gives some general best practices.
If the size of your application is to high to be published on the market, you'll can either
ship your app without the images and load them from the internet to the phones SD-card when the app is first started
Use Androids own APK Extension Files, which is basically the same but you don't have to do everything yourself.
Use pngquant or posterizer to reduce size of PNG images (these tools are lossy, but give significant savings).
You can also optimize them with PNGOUT, which is one of the best lossless optimizers.
I've written Mac GUI for those.
Always use PNG (.png) images.
And compress it online by uploading your images to
https://tinypng.com/
Simple and sober, always work. You are welcome. :)
There is also a better way to use AndEngine, it saves you from making layout for each phone. And there is no need to use different images for different dpi phones.
Do you use 9-patches for backgrounds? Also you can use imagemagick or anything similar to compress a batch or images.
Try and use ".png".
Use 9-patch images for backgrounds.
If you have title bars, headers with vertical gradients, always use 1-pixel width gradient images. This is a super saver.
If you manage to get hold of Photoshop, they have the option to save images for web/mobile devices. Helps in making really small sized images with good quality.
If u r supporting multiple devices, maintain different versions of the images only for those that are really necessary.