2012-01-03 131 views
1

在我的应用程序中我动态缩放图像到其原始大小的50%。缩放时显示某种平铺(下图显示)。图像的正方形部分比邻近的应该具有相同颜色的图块更亮。它几乎没有引人注意,但对于我的应用来说这还不够好。正方形的大小取决于比例因子。所以在75%的尺寸下,瓷砖更小。缩放图像显示某种平铺

例子:

enter image description here

我的绘制代码(被称为onDraw有我的自定义视图):

private void drawImage(Bitmap bitmap, float scaling, 
     Canvas canvas, float offset) 
{ 

    Matrix p = new Matrix(); 
    Matrix m = new Matrix(); 
    Matrix y = new Matrix(); 
    Matrix o = new Matrix(); 

    p.setTranslate(-bitmap.getWidth()/2, -bitmap.getHeight()/2); 

    // translation to views center (minus half height of image 
    // so that the bottom of the picture is in the views center. 
    y.setTranslate(getWidth()/2, getHeight()/2); 
    // offset translation. 
    o.setTranslate(offset, 0); 

    m.setScale(scaling, scaling); 
    m.preConcat(p); 
    m.postConcat(y); 
    m.postConcat(o); 

    // draw image 
    canvas.drawBitmap(bitmap, m, null); 
} 

有谁知道如何防止瓦片?

+0

您可以尝试使用“Bitmap.createScaledBitmap()”对位图进行预分频,而不是在旅途中对其进行缩放并查看是否有帮助。 – Jave 2012-01-03 10:40:53

+1

你尝试过'canvas.drawBitmap(位图,m,新的Paint(Paint.FILTER_BITMAP_FLAG))',见[这里](http://stackoverflow.com/a/7468636/662732) – fab 2012-01-03 10:42:55

+0

@Jave:由于图像是动态缩放其原始大小的100%至50%预缩放对我来说毫无用处。 – 2012-01-03 10:49:47

回答

1

您是否试过canvas.drawBitmap(bitmap, m, new Paint(Paint.FILTER_BITMAP_FLAG))如图所示here

1

您是在设备上还是在模拟器中看到它?因为在一个设备上,一些低质量的GPU可能会导致缺乏GPU或仿真器的设备无法产生的“抖动”效果。

解决方案是在Photoshop中或使用Bitmap API预先缩放图像。

+0

我在Acer A500平板电脑上运行。由于图像在原始大小的100%和50%之间动态缩放,预缩放对我来说是无用的。 – 2012-01-03 10:46:30