我使用的是Crosswalk库而不是常规的WebView。我需要在打印机中打印收据,我发送字节。为此,我想将页面转换为图像,然后将其打印出来。这就是我试过的:
public void onLoadFinished(XWalkView view, String url) {
super.onLoadFinished(view, url);
Log.d(TAG, "Load Finished:" + url);
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
FileOutputStream fos = null;
try {
fos = new FileOutputStream( "/sdcard/" + "page.jpg" );
if ( fos != null ) {
b.compress(Bitmap.CompressFormat.JPEG, 90, fos );
fos.close();
}
}
catch( Exception e ) {
System.out.println("-----error--"+e);
}
}
如何捕获页面到图像?
答案 0 :(得分:0)
感谢使用Crosswalk。 您可以尝试此API:
/**
* Capture a bitmap of visible content.
* @param callback callback to call when the bitmap capture is done.
* @since 6.0
*/
public void captureBitmapAsync(XWalkGetBitmapCallback callback)