how can I convert a Picture into a Bitmap, what I tried in the code is not working. Any Ideas on how to do this? I wanted to get the image in the Picture object and put that image into the ImageView named imageOne.
showBitmap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Picture picture = wv.capturePicture();
Bitmap bm = Bitmap.createBitmap(picture.getWidth(),
picture.getHeight(),
Bitmap.Config.RGB_565);
Canvas c = new Canvas(bm);
picture.draw(c);
imageOne.setImageBitmap(bm);
}
});
Add this:
//Convert Picture to Bitmap
private static Bitmap pictureDrawable2Bitmap(Picture picture) {
PictureDrawable pd = new PictureDrawable(picture);
Bitmap bitmap = Bitmap.createBitmap(pd.getIntrinsicWidth(), pd.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pd.getPicture());
return bitmap;
}
Reference: Android - How to convert picture from webview.capturePicture() to byte[] and back to bitmap
Then modify your code as follows:
showBitmap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Picture picture = wv.capturePicture();
Bitmap bm = pictureDrawable2Bitmap(picture);
imageOne.setImageBitmap(bm);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With