所以,简单的任务:我有一张大图,它有透明的部分。我想使用 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);