調(diào)整大小/縮放位圖后圖像質(zhì)量不佳我正在寫一個(gè)紙牌游戲,需要我的卡在不同的情況下有不同的尺寸。我將我的圖像存儲(chǔ)為位圖,以便可以快速繪制和重繪(用于動(dòng)畫)。我的問題是,無(wú)論我如何嘗試和縮放我的圖像(無(wú)論是通過matrix.postScale,matrix.preScale還是createScaledBitmap函數(shù)),它們總是出現(xiàn)像素化和模糊。我知道它導(dǎo)致問題的縮放因?yàn)樵跊]有調(diào)整大小的情況下繪制時(shí)圖像看起來很完美。但還是沒有到達(dá)任何地方。我用這段代碼存儲(chǔ)我的位圖(到一個(gè)hashmap):cardImages = new HashMap<Byte, Bitmap>();cardImages.put(GameUtil.hearts_ace, BitmapFactory.decodeResource(r, R.drawable.hearts_ace));并使用此方法繪制它們(在Card類中):public void drawCard(Canvas c){
//retrieve the cards image (if it doesn't already have one)
if (image == null)
image = Bitmap.createScaledBitmap(GameUtil.cardImages.get(ID),
(int)(GameUtil.standardCardSize.X*scale), (int)(GameUtil.standardCardSize.Y*scale), false);
//this code (non-scaled) looks perfect
//image = GameUtil.cardImages.get(ID);
matrix.reset();
matrix.setTranslate(position.X, position.Y);
//These methods make it look worse
//matrix.preScale(1.3f, 1.3f);
//matrix.postScale(1.3f, 1.3f);
//This code makes absolutely no difference
Paint drawPaint = new Paint();
drawPaint.setAntiAlias(false);
drawPaint.setFilterBitmap(false);
drawPaint.setDither(true);
c.drawBitmap(image, matrix, drawPaint);}任何見解將不勝感激。謝謝
調(diào)整大小/縮放位圖后圖像質(zhì)量不佳
喵喵時(shí)光機(jī)
2019-08-26 14:35:25