Created
August 14, 2014 09:12
-
-
Save terrytowne/0f32995915328c31a70c to your computer and use it in GitHub Desktop.
Android save WebView rendered picture.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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