Skip to content

Instantly share code, notes, and snippets.

@terrytowne
Created August 14, 2014 09:12
Show Gist options
  • Save terrytowne/0f32995915328c31a70c to your computer and use it in GitHub Desktop.
Save terrytowne/0f32995915328c31a70c to your computer and use it in GitHub Desktop.
Android save WebView rendered picture.
ImageView imageview;
WebView webview;
class Background extends AsyncTask<Void, Void, Bitmap>
{
@Override
protected Bitmap doInBackground(Void... params)
{
try
{
Thread.sleep(2000);
Bitmap bitmap = Bitmap.createBitmap(webview.getWidth(), webview.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
webview.draw(canvas);
return bitmap;
}
catch (InterruptedException e){}
catch (Exception e){}
return null;
}
@Override
protected void onPostExecute(Bitmap result)
{
imageview.setImageBitmap(result);
}
}
webview.setWebChromeClient(new WebChromeClient()
{
public void onProgressChanged(WebView view, int progress)
{
if(progress==100)
new Background().execute();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment