I want to save the picture getting from capturePicture method in WebView
how to do this?
web = new WebView(this);
web.setPictureListener(new PictureListener(){
public void onNewPicture(WebView view, Picture picture) {
if(picture != null)
{
try
{
Bitmap bmp = pictureDrawable2Bitmap(new PictureDrawable(picture));
FileOutputStream out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
web.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView webview, String url) {
Picture picture = webview.capturePicture();
}
});
web.getSettings().setJavaScriptEnabled(true);
setContentView(web);
helper function
private static Bitmap pictureDrawable2Bitmap(PictureDrawable pictureDrawable){
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth()
,pictureDrawable.getIntrinsicHeight()
, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
return bitmap;
}
Disclaimer: I haven't actually compiled this, it should work though
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