本文整理了Java中android.webkit.WebView.getDrawingCache()
方法的一些代码示例,展示了WebView.getDrawingCache()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.getDrawingCache()
方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:getDrawingCache
暂无
代码示例来源:origin: airbnb/AirMapView
@Override public void getSnapshot(OnSnapshotReadyListener listener) {
boolean isDrawingCacheEnabled = webView.isDrawingCacheEnabled();
webView.setDrawingCacheEnabled(true);
// copy to a new bitmap, otherwise the bitmap will be
// destroyed when the drawing cache is destroyed
// webView.getDrawingCache can return null if drawing cache is disabled or if the size is 0
Bitmap bitmap = webView.getDrawingCache();
Bitmap newBitmap = null;
if (bitmap != null) {
newBitmap = bitmap.copy(Bitmap.Config.RGB_565, false);
}
webView.destroyDrawingCache();
webView.setDrawingCacheEnabled(isDrawingCacheEnabled);
listener.onSnapshotReady(newBitmap);
}
}
代码示例来源:origin: hsk256/WebviewCapture
private void getSnapshot() {
bitmap = webView.getDrawingCache();
Log.d(TAG,"bitmap--"+bitmap);
try {
String fileName = Environment.getExternalStorageDirectory().getPath()+"/webview_capture3.jpg";
FileOutputStream fos = new FileOutputStream(fileName);
//压缩bitmap到输出流中
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos);
fos.close();
Toast.makeText(WebviewFromDrawCache.this, "截屏成功", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}finally {
//bitmap.recycle();
}
}
代码示例来源:origin: stackoverflow.com
public File getBitmapFromwebchartView(WebView view2) {
File fi;
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
代码示例来源:origin: stackoverflow.com
public File getBitmapFromwebchartView(WebView view2) {
File fi = null;
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
//fi = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
代码示例来源:origin: stackoverflow.com
Sry replace the function with this code
public File getBitmapFromwebchartView(WebView view2) {
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fl = new File(Environment.getExternalStorageDirectory(),
"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fl);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fl;
}
代码示例来源:origin: stackoverflow.com
public File getBitmapFromwebchartView(WebView view2) {
File fi;
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fi = new File(Environment.getExternalStorageDirectory(), "Screenshot" + ".jpg");
//fi = new File(Environment.getExternalStorageDirectory(),"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fi);
b.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fi;
}
代码示例来源:origin: stackoverflow.com
Use this Code to get the screen shot of web view
public File getBitmapFromwebchartView(WebView view2) {
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
try {
fl = new File(Environment.getExternalStorageDirectory(),
"Realitycheck" + ".jpg");
// write the bytes in file
FileOutputStream fo;
fo = new FileOutputStream(fl);
newbitmap.compress(CompressFormat.JPEG, 95, fo);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return fl;
}
Use this code and get the required file stored in sdcard.
代码示例来源:origin: stackoverflow.com
public static Bitmap getBitmapForVisibleRegion(WebView webview) {
Bitmap returnedBitmap = null;
webview.setDrawingCacheEnabled(true);
returnBitmap = Bitmap.createBitmap(webview.getDrawingCache());
webview.setDrawingCacheEnabled(false);
return returnedBitmap;
}
代码示例来源:origin: stackoverflow.com
mWebView.setDrawingCacheEnabled(true);
Bitmap bm= mWebView.getDrawingCache();
代码示例来源:origin: stackoverflow.com
if (view2 != null) {
view2.setDrawingCacheEnabled(true);
Bitmap b = view2.getDrawingCache();
if (b != null) {
代码示例来源:origin: stackoverflow.com
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
imgView = (ImageView) findViewById(R.id.imageview);
webView = (WebView) findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/test.jpg");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
imgView.setImageBitmap(getBitmapForVisibleRegion(webView));
}
});
}
public static Bitmap getBitmapForVisibleRegion(WebView webview) {
Bitmap returnedBitmap = null;
webview.setDrawingCacheEnabled(true);
returnedBitmap = Bitmap.createBitmap(webview.getDrawingCache());
webview.setDrawingCacheEnabled(false);
return returnedBitmap;
}
内容来源于网络,如有侵权,请联系作者删除!