Reputation: 46
I'm extending SurfaceView to create a fullscreen horizontally scrollable background.
My issue is with the quality of the bitmap. When used in the draw-call as
canvas.drawBitmap(bitmap, 0, 0, paint);
It's quality is much poorer than its original. I'm not doing any scaling.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image, options);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setFilterBitmap(true);
Not sure if the images show it clearly, they're screenshots from the tablet. The good one is an ImageView with its src as the drawable.
The canvas one has this horizontally stripy effect, its very significant in reality. This effect is vertical as well. It's whenever the gradient is slightly changing. As if the canvas' bitmap has much less colors..
I'm sure there's a solution to this, but I could not find any.
Upvotes: 2
Views: 1215
Reputation: 52313
Looks like color quantization. The default color format for SurfaceView is 16-bit RGB_565. Change it to 32-bit with something like this on onCreate()
:
mSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
(Some examples use PixelFormat.TRANSLUCENT
.)
Upvotes: 1