Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SurfaceView Bitmap quality is worse than ImageView in XML

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.

like image 435
Greyshack Avatar asked Nov 27 '25 04:11

Greyshack


1 Answers

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.

like image 107
Greyshack Avatar answered Nov 28 '25 18:11

Greyshack