When I draw a bitmap on a SurfaceView by a draw method the image(background in this case) is blurry and bad quality, even though it is not scaled up. When I use the same image as background in an XML layout it looks way better, sharper.
This is the code I use to load a bitmap:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inPreferQualityOverSpeed = true;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bmpLoader = BitmapFactory.decodeResource(getResources(), R.drawable.image);
bmpImage= Bitmap.createScaledBitmap(bmpLoader,width, height,true);
if (bmpLoader!=null){
bmpLoader.recycle();
bmpLoader = null;
}
And also I use a special paint for painting bitmaps:
bitmapPaint = new Paint();
bitmapPaint.setAntiAlias(true);
bitmapPaint.setDither(true);
bitmapPaint.setFlags(Paint.DITHER_FLAG);
bitmapPaint.setFilterBitmap(true);
Thanks in advance for any suggestions.
In case someone has the same problem: You have to call and set this pixel format
yoursurfaceviewinstance.getHolder().setFormat(PixelFormat.RGBA_8888);
before you set your content view to this surface view.
In case someone has the same problem: You have to call and set this pixel format
yoursurfaceviewinstance.getHolder().setFormat(PixelFormat.RGBA_8888);
before you set your content view to this surface view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With