Search code examples
androidimagenoise

Android - noise in saved images


My Android application loads images, does some processing and saves the processed images on the SD card. I save temporary files to the SD card instead of using buffers. For example, reading a background, scrolling the image, drawing an annotation, merging background and annotation in a saved temp file to use as next background, and so forth. Typical snippets:

bitmap = Bitmap.createBitmap(imageSizeX, imageSizeY, Bitmap.Config.ARGB_8888);

bitmap = BitmapFactory.decodeFile(path, options);

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);

Everything works fine but in some cases the saved images have added noise similar to that described in this post: Bitmap resizing and rotating: linear noise

The author of the post cited solved the problem by subsampling, but I don't wish to do that.

I have tried the solutions suggested here: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/#more-1218 which if I understand correctly should be achieved by setting: getWindow().setFormat(PixelFormat.TRANSLUCENT); to force 32 bit.

which does not change much. Setting or not setting the dither flag does not seem to change much either. Any other ideas?


Solution

  • In answer to my own question: The noise disappears, or at least the result is way better, by compressing to .png instead of .jpg

    bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
    

    The same sky which looks like a carpet texture in .jpg looks smooth and clean in .png. Since the difference is much more evident than the usual difference between the same image compressed to .png and .jpg, I guess it depends on the Android implementation. Setting explicitly TRANSLUCENT and DITHER does not make much difference one way or another.