2015-09-28 37 views
3

我必須嘗試刪除旋轉圖像後的黑色背景在我的代碼我如何能在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中顯示黑色背景。

enter image description here

+0

檢查我的答案:http://stackoverflow.com/a/38868813/3640366 – WoookLiu

+0

仍然無法正常工作,它會得到黑色背景後面的圖像。感謝您的答覆。 –

+0

你可以在這裏發佈你的代碼嗎? – WoookLiu

回答

1

您必須使用resizedBitmap.setHasAlpha(true); 把該行的代碼之後,你宣佈你的位圖。