所以,简单的任务:我有一张大图,它有透明的部分。我想使用BitmapRegionDecoder方法decodeRegion将矩形部分解码为位图。虽然图片的非透明部分被很好地解码,但我得到一些废话而不是透明部分。有人面对熟悉的事吗?我使用的代码:
// colNumber, rowNumber are some proper integers from 0 to 4
InputStream is = playingTable.getResources().openRawResource(R.drawable.picture);
try {
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false);
int cellWidth = decoder.getWidth() / 5;
int cellHeight = decoder.getHeight() / 5;
Rect rect = new Rect(colNumber * cellWidth, rowNumber * cellHeight, (colNumber + 1) * cellWidth, (rowNumber + 1) * cellHeight);
bmp = decoder.decodeRegion(rect, null);
is.close();
} catch (IOException e) {
Log.i("Exception: ", e.toString());
}
// in draw method:
canvas.drawBitmap(bmp, x, y, null);