Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android bitmap quality issues

Tags:

android

bitmap

In my app, the bitmap is drawn as if the color is some lower quality type. If i load up the background image using the gallery app, it loads just fine and does not look like it's super low quality. The code i am using to load and draw my images is simple:

//Code for initializing the Bitmap
Bitmap bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.none), (int) (canvas.getWidth() * compression), (int) (canvas.getHeight() * compression), true);
//...
//Code for drawing this Bitmap
canvas.drawBitmap(bitmap, null, new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), null);

If nothing in the code tells you what is wrong, i made an image comparing what the image actually looks like on a computer or other image viewer, and what it looks like in the app. Top image is the app on the phone, bottom image is what the background image actually looks like. Notice the lines on the top image. What is up with that?

like image 751
Mohammad Adib Avatar asked May 12 '12 23:05

Mohammad Adib


People also ask

How do I increase the quality of a bitmap image?

Use lossless compression for the bitmap. In the Library window, right-click (Windows) or control-click (Macintosh) on the bitmap and select Properties. Choose Lossless from the Compression pop-up menu and click OK.

What happens to image quality when bitmaps are scaled?

As you may have guessed, the more pixels in the image and the higher the resolution is, the higher quality the image will be. For example, if we scale a raster image to enlarge it, without changing resolution, it will lose quality and look blurry or pixilated.

How do you handle bitmap in Android as it takes too much memory?

Choose the most appropriate decode method based on your image data source. These methods attempt to allocate memory for the constructed bitmap and therefore can easily result in an OutOfMemory exception. Each type of decode method has additional signatures that let you specify decoding options via the BitmapFactory.


1 Answers

question is somewhat similar to Bad image quality after resizing/scaling bitmap

try disabling scaling, resize in an offscreen bitmap and make sure that Bitmap is 32 bits (ARGB888):

Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);

another good and complete answer about image scaling/processing can be found at Quality problems when resizing an image at runtime

like image 60
Shine Avatar answered Sep 22 '22 13:09

Shine