Created
September 14, 2016 04:54
-
-
Save ashmeh6/712eee24125c7fbfd30deafa5e0a3323 to your computer and use it in GitHub Desktop.
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
webView.setWebViewClient(new WebViewClient() { | |
public void onPageFinished(WebView view, String url) { | |
// do your stuff here | |
webView.measure(View.MeasureSpec.makeMeasureSpec( | |
View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED), | |
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); | |
webView.layout(0, 0, webView.getMeasuredWidth(), | |
webView.getMeasuredHeight()); | |
webView.setDrawingCacheEnabled(true); | |
webView.buildDrawingCache(); | |
Bitmap bm = Bitmap.createBitmap(webView.getMeasuredWidth(), | |
webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888); | |
Canvas bigcanvas = new Canvas(bm); | |
Paint paint = new Paint(); | |
int iHeight = bm.getHeight(); | |
bigcanvas.drawBitmap(bm, 0, iHeight, paint); | |
webView.draw(bigcanvas); | |
System.out.println("1111111111111111111111=" | |
+ bigcanvas.getWidth()); | |
System.out.println("22222222222222222222222=" | |
+ bigcanvas.getHeight()); | |
if (bm != null) { | |
try { | |
String path = Environment.getExternalStorageDirectory() | |
.toString(); | |
OutputStream fOut = null; | |
File file = new File(path, "/aaaa.png"); | |
fOut = new FileOutputStream(file); | |
bm.compress(Bitmap.CompressFormat.PNG, 50, fOut); | |
fOut.flush(); | |
fOut.close(); | |
bm.recycle(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment