2011-06-26 72 views
0

我想從.png資源文件中繪製圖像。Android:在顯示ImageView和在畫布上繪圖時的外觀差異

我試過2種方法。當創建的ImageView和分配它R.drawable - 圖像看起來罰款:

enter image description here

但是當我畫的像自己的畫布上用下面的代碼:

BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
options.inDither = false; 
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.img, options);    
canvas.drawBitmap(bmp, x, y, null); 

圖像看起來像這樣:

enter image description here

,如果你會發現,有淺灰色垂直林在圖像內部。

有誰知道,爲什麼這兩種方法之間的外觀差異?

謝謝, 亨利。

回答

0

找到第三種方式,保留圖像質量。

Drawable drawable = getResources().getDrawable(R.drawable.img); 
drawable.setBounds(x, y, x + CELL_WIDTH - 1, y + CELL_HEIGHT -1); 
drawable.draw(canvas);