Android中,SurfaceView上的位图质量比XML布局中的ImageView差。

3
当我通过绘制方法在SurfaceView上绘制位图时,图像(在这种情况下是背景)会模糊且质量很差,即使它没有被放大。当我在XML布局中使用相同的图像作为背景时,它看起来更好,更清晰。这是我用于加载位图的代码:
    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;
        }

我还使用一种特殊的颜料来绘制位图:

    bitmapPaint = new Paint();
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFlags(Paint.DITHER_FLAG);
    bitmapPaint.setFilterBitmap(true);

感谢您提供的任何建议。

如果有人遇到相同的问题: 您需要调用并设置此像素格式。

    yoursurfaceviewinstance.getHolder().setFormat(PixelFormat.RGBA_8888);

在将内容视图设置到该表面视图之前。
1个回答

2
如果有人遇到相同的问题: 您需要调用并设置此像素格式。
    yoursurfaceviewinstance.getHolder().setFormat(PixelFormat.RGBA_8888);

在将内容视图设置为此表面视图之前,请注意。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接