繁体   English   中英

如何将混合应用程序的当前视图获取到位图

[英]How to get the current view of the hybrid app to a bitmap

如何获取与Android中位图混合(本机+ HTML)的应用程序的当前视图?

此方法只能提供本机元素:

public static Bitmap getScreenShot(View view) {
    View screenView = view.getRootView();
    screenView.setDrawingCacheEnabled(true);
    Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
    screenView.setDrawingCacheEnabled(false);
    return bitmap;
}

// View to BitMap
Bitmap b  = getScreenShot(getWindow().getDecorView().findViewById(android.R.id.content));

我们如何才能将混合元素(当前显示的本机视图+ HTML内容)转换为位图?

该代码就足够了。 HTML内容位于本机视图WebView中。 将WebView传递到该代码中,您将获得html的位图。 请注意,这里很容易遇到OOM问题-HTML内容通常以像素为单位非常大。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM