[英]How to remove black background that comes after rotating bitmap?
How to remove black background that comes after rotating bitmap
?. 如何删除
rotating bitmap
后出现的黑色背景? I have tried different methods but none of them seems to work. 我尝试了不同的方法,但似乎都没有用。 Please help me find a way out!
请帮助我找到出路!
This is my code it produces 这是我产生的代码
image:
图片:
<!-- language: lang-java -->
if (view.getId() == R.id.save_btn) {
emojiOn = false;
timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
drawView.setDrawingCacheEnabled(true);
if (drawView.getDrawingCache() != null)
drawView.destroyDrawingCache();
drawView.buildDrawingCache();
AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
saveDialog.setTitle("Save drawing");
saveDialog.setMessage("Save drawing to device Gallery?");
saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Matrix matrix = new Matrix();
matrix.setRotate(Rotation);
Bitmap b = drawView.getDrawingCache();
b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
String imgSaved = MediaStore.Images.Media.insertImage(getContentResolver(), b, timeStamp, "drawing");
if (imgSaved != null)
Toast.makeText(getApplicationContext(), "Drawing saved to gallery!", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "Oops! Image could not be saved.", Toast.LENGTH_SHORT).show();
drawView.destroyDrawingCache();
}
});
saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
saveDialog.show();
}
You must use your bitmap object b.setHasAlpha(true);
您必须使用位图对象
b.setHasAlpha(true);
put that line of code right after you declare your bitmap. 在声明位图后立即添加该行代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.