我正在使用 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);
}
}
如何将页面捕获到图像?