简体   繁体   English

如何在Android 5.0中删除旋转位图图像后的黑色背景

[英]How can i remove black background of after rotate Bitmap image in android 5.0

i have try to remove the black background after the rotate image in my code 我试图在我的代码中旋转图像后删除黑色背景

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;
}

how can i remove black background i have seen that only in my android lolipop , i also try in my emulator Google galaxy nexus - 4.2.2 in that black background is not display . 我怎么能删除黑色背景我已经看到只有在我的Android lolipop,我也尝试在我的模拟器谷歌galaxy nexus - 4.2.2在黑色背景不显示。

在此输入图像描述

You must use resizedBitmap.setHasAlpha(true); 你必须使用resizedBitmap.setHasAlpha(true); put that line of code right after you declare your bitmap. 在声明位图后立即放置该行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM