I was trying to drawbitmap on a canvas. In the emulator, it seems that the image is blurred. Is it likely that the android automatically scaled the bitmap? I did try to disable the scaling such as
< supports-screens android:smallScreens="false" android:normalScreens="true"
android:largeScreens="false" android:xlargeScreens="false" android:anyDensity="true" />
blur means if I have a pixel in the bitmap, I am seeing like 2x2 pixel. soemtimes a pixel is missing. so I assumed that Android automatically scaled it to fit different screens. I am just use WVGA and how do I prevent this scaling? Thanks.
Indeed, both
Bitmap
andCanvas
have a density property, drawing a bitmap automatically scales the bitmap if the densities of the canvas and bitmap differ.From Bitmap.setDensity() documentation:
You can call
bitmap.setDensity(Bitmap.DENSITY_NONE)
to disable this automatic scaling behavior altogether. If you load the bitmap from resources, placing it underdrawable-nodpi
should be enough.For the curious: the logic behind this behavior is implemented in
Canvas.cpp
(native part of theandroid.graphics.Canvas
), in thedrawBitmap__BitmapFFPaint()
method:I think put you bitmap in drawable-nodpi folder will fix this problem. BTW, tag only be used by Google Play.