How to convert a PictureDrawable to a Bitmap? I tried the following code shown below and it gives a null pointer.
//Convert PictureDrawable to Bitmap private Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable){ Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888); Toast.makeText(HTMLActivity.this, "bitmap " + bitmap.toString(), Toast.LENGTH_LONG).show(); Canvas canvas = new Canvas(bitmap); canvas.drawPicture(pictureDrawable.getPicture()); return bitmap; }
Here is an example to show what I am doing in my code;
private Picture picture; private String url; private WebView webview; private Bitmap HTMLBitmap; private PictureDrawable HTMLPicDraw; // goal is to convert WebView --> Picture --> PictureDrawable --> Bitmap picture = webview.capturePicture(); HTMLPicDraw = new PictureDrawable(picture); // HTMLPicDraw a PictureDrawable object is good, no null pointer exception here // what is left is to go from PictureDrawable to Bitmap
source share