【问题标题】:Android SurfaceView Bitmap quality is worse than ImageView in XMLAndroid SurfaceView Bitmap 质量比 XML 中的 ImageView 差
【发布时间】:2014-12-19 16:45:09
【问题描述】:

当我通过 draw 方法在 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);

在将内容视图设置为此表面视图之前。

【问题讨论】:

    标签: android xml image bitmap surfaceview


    【解决方案1】:

    如果有人遇到同样的问题: 您必须调用并设置此像素格式

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

    在将内容视图设置为此表面视图之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 2017-03-28
      • 2012-05-14
      • 1970-01-01
      相关资源
      最近更新 更多