2
我試圖捕獲webview,但是當我試圖壓縮位圖webview凍結。我嘗試了很多,但沒有找到解決方案。請幫助..Webview在Android中凍結
下面是一些代碼:
webview.getHeight();
Picture p = webview.capturePicture();
webview.setDrawingCacheEnabled(true);
Bitmap bitmap = pictureDrawable2Bitmap(p);
webview.setDrawingCacheEnabled(false);
String fname = System.currentTimeMillis() + ".png";
File file1 = new File(fname);
try
{
FileOutputStream out = new FileOutputStream(file1);
bitmap.compress(Bitmap.CompressFormat.PNG, 10, out);
out.flush();
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
private static Bitmap pictureDrawable2Bitmap(Picture picture)
{
PictureDrawable pictureDrawable = new PictureDrawable(picture);
Bitmap bitmap = null;
try
{
bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
}
catch (Exception e)
{
e.printStackTrace();
}
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
return bitmap;
}