在我的應用程序中我動態縮放圖像到其原始大小的50%。縮放時顯示某種平鋪(下圖顯示)。圖像的正方形部分比鄰近的應該具有相同顏色的圖塊更亮。它幾乎沒有引人注意,但對於我的應用來說這還不夠好。正方形的大小取決於比例因子。所以在75%的尺寸下,瓷磚更小。縮放圖像顯示某種平鋪
例子:
我的繪製代碼(被稱爲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);
}
有誰知道如何防止瓦片?
您可以嘗試使用「Bitmap.createScaledBitmap()」對位圖進行預分頻,而不是在旅途中對其進行縮放並查看是否有幫助。 – Jave 2012-01-03 10:40:53
你嘗試過'canvas.drawBitmap(位圖,m,新的Paint(Paint.FILTER_BITMAP_FLAG))',見[這裏](http://stackoverflow.com/a/7468636/662732) – fab 2012-01-03 10:42:55
@Jave:由於圖像是動態縮放其原始大小的100%至50%預縮放對我來說毫無用處。 – 2012-01-03 10:49:47