2015-12-14 91 views
1

我試圖將視圖轉換爲位圖,但我失去了黑色。我將是這樣的:Android將視圖轉換爲BitMap

Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(),view.getHeight(), Bitmap.Config.ARGB_8888); 

Example

我怎麼能轉換爲位圖,這樣的百分比值的黑色不丟失?

感謝, 問候

回答

2

嗨,你可以用這個方法來查看轉換爲位圖

private Bitmap createBitmapFromView(Context context, View view) { 
     DisplayMetrics displayMetrics = new DisplayMetrics(); 
     ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
     view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

     view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels); 
     view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels); 
     view.buildDrawingCache(); 
     Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); 

     Canvas canvas = new Canvas(bitmap); 
     view.draw(canvas); 

     return bitmap; 
    } 
+0

仍然可以得到數量得到黑色的背景,檢查圖像請。 – user3111591

+0

http://stackoverflow.com/questions/34315729/android-bitmap-dont-refresh你能幫助這個嗎? – user3111591