2
Webviewについて質問があります。ウェブビューをキャプチャするとき、ビューを表示しないコンテンツは白です。
これは私のソースと結果です。
private void saveDocumentImage() {
WebView wv = arrWebView.get(0);
wv.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int y=wv.getHeight();
Bitmap captureView = Bitmap.createBitmap(wv.getMeasuredWidth(), wv.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
wv.layout(0, 0, wv.getMeasuredWidth(), wv.getMeasuredHeight());
Canvas screenShotCanvas = new Canvas(captureView);
wv.draw(screenShotCanvas);
if (captureView != null) {
try {
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path, "temp");
if (!file.exists())
file.mkdirs();
fOut = new FileOutputStream(path + "/temp/test_0.jpg");
captureView.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
wv.setDrawingCacheEnabled(false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
wv.destroyDrawingCache();
captureView.recycle();
captureView=null;
}
ここでは私と同じです。 :https://stackoverflow.com/questions/37023619/capturing-bitmap-android-chromium-webview-returns-content-as-white
あなたのおかげでありがとう。私は今それを解決しました。 lol オプション 'webview.enableSlowWholeDocumentDraw();'が必要ですアンドロイドデベロッパーから見つけました。 と私は新しい問題があります。あなたは私を助けることができますか? 全景を切り抜こうと思っていますが、うまくいきませんでした...それは私のソースです 切り取りのために追加しました。 'bitmap = Bitmap.createBitmap(ビットマップ、0,2000、wv.getMeasuredWidth()、4000);' ビットマップが2000から4000まで表示されることを望みますが(x協力します)、0から4000まで表示されます。 – Adrian
createBitmap(ビットマップソース、int x、int y、int幅、int高さ) createBitmap 、0,2000、wv.getMeasuredWidth()、4000); 最後の2つのパラメータで新しく作成されたビットマップの高さと幅が決まります。http://stackoverflow.com/questions/9747295/crop-particle-of-image-in-android http:// www.coderzheaven.com/2011/03/15/crop-an-image-in-android/ –
特にこのサイトからhttp://www.coderzheaven.com/2011/03/15/crop-an-image-in -android/ –