如何在 android 5.0 中删除旋转位图图像后的黑色背景
How can i remove black background of after rotate Bitmap image in android 5.0
我已经尝试在我的代码中删除旋转图像后的黑色背景
Bitmap rotate(float x, Bitmap bitmapOrg) {
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(x);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,height, matrix, true);
//Canvas canvas = new Canvas(resizedBitmap);
//canvas.drawColor(Color.TRANSPARENT);
return resizedBitmap;
}
如何删除黑色背景 我只在我的 android lolipop 中看到过,我也在我的模拟器 Google galaxy nexus - 4.2.2 中尝试过该黑色背景不显示。
你必须使用 resizedBitmap.setHasAlpha(true);
在声明位图后立即放置该行代码。
我已经尝试在我的代码中删除旋转图像后的黑色背景
Bitmap rotate(float x, Bitmap bitmapOrg) {
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(x);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,height, matrix, true);
//Canvas canvas = new Canvas(resizedBitmap);
//canvas.drawColor(Color.TRANSPARENT);
return resizedBitmap;
}
如何删除黑色背景 我只在我的 android lolipop 中看到过,我也在我的模拟器 Google galaxy nexus - 4.2.2 中尝试过该黑色背景不显示。
你必须使用 resizedBitmap.setHasAlpha(true);
在声明位图后立即放置该行代码。