【问题标题】:Convert HTML to Bitmap将 HTML 转换为位图
【发布时间】:2020-05-18 15:27:40
【问题描述】:

我有一个用 react.js 编写的应用程序,我想将编码 base 64 HTML 发送到 android 设备。 android 设备必须解码 HTML 代码并将其更改为位图。我无法弄清楚那部分(将 HTML 转换为位图);谁能帮我?我现在正在尝试使用 webview,但 webview 不会从 html 中获取数据。

WebView webview = New WebView(getApplicationContext());
webview.getSettings().setJavaScriptEnabled(True);
webview.loadDataWithBaseURL("", encodedHtml, "text/html", "base64", "");
shareResultAsImage(webview);

【问题讨论】:

    标签: java android html android-studio


    【解决方案1】:

    可以使用WebView的onDraw()方法获取图片:

    Bitmap bitmap = Bitmap.createBitmap(...);
    Canvas canvas = new Canvas(bitmap);
    webView.onDraw(canvas);
    

    【讨论】:

    • 即使我使用画布,我也需要我的 webView 来获取数据。现在我无法将数据添加到 webView 。 webView.loadUrl("docs.google.com/gview?embedded=true&url=file:///…); 即使这样,我的 webView 也没有获取任何数据
    • 为什么需要 docs.google.com 在资产中打开文件?它肯定不会起作用。使用 webView.loadUrl("file:///android_asset/test.html");
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 2010-10-14
    • 2012-07-23
    相关资源
    最近更新 更多