0
我需要繪製在另一個位圖上調整大小的位圖(縮小一個位圖,然後在另一個位圖上繪製它)。Android在另一個位圖上繪製已調整大小的位圖
我使用的是現在的代碼是:
Resources res = ((Context)(activity)).getResources();
Drawable[] layers = new Drawable[2];
layers[0] = res.getDrawable(R.drawable.marker_report_red);
layers[1] = new BitmapDrawable(getResizedBitmap(((BitmapDrawable)res.getDrawable(R.drawable.report_path_merge_ic)).getBitmap(),10,10));
LayerDrawable layerDrawable = new LayerDrawable(layers);
Bitmap b = Bitmap.createBitmap(layers[0].getIntrinsicWidth(), layers[0].getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
layerDrawable.setBounds(0, 0, layers[0].getIntrinsicWidth(), layers[0].getIntrinsicHeight());
layerDrawable.draw(new Canvas(b));
和:
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
return resizedBitmap;
}
但產生的圖像只顯示了被拉伸到一個基本的規模模糊的位圖。
我該怎麼做?這是第4個方法,我想......