android - 自定义 html 视图以支持 android textview 中的图像。Web 视图在 base64 图像中加载非常慢
问题描述
我想使用 nativescript 的 htmlview 来渲染 base64encoded 图像。有没有办法自定义htmlview,因为有很多文章支持android textview中的图像,而nativescript htmlview被包裹在android textview上
我试过,使用通过android的fromHtml方法插入base64图像的方法,但没有一个有效。它显示 [obj] 而不是图像
getSafe(text: string, view: any) { let context = view._context;
let d = new android.text.Html.ImageGetter({
// @Override
getDrawable(source: string): android.graphics.drawable.Drawable {
let base_64_source: string = source.replace(/data.*base64/g, "");
const data = android.util.Base64.decode(
base_64_source,
android.util.Base64.DEFAULT
);
const bitmap: android.graphics.Bitmap = android.graphics.BitmapFactory.decodeByteArray(
data,
0,
data.length
);
let image: android.graphics.drawable.Drawable = new android.graphics.drawable.BitmapDrawable(
context.getResources(),
bitmap
);
image.setBounds(
0,
0,
0 + image.getIntrinsicWidth(),
0 + image.getIntrinsicHeight()
);
return image;
// return new android.graphics.drawable.BitmapDrawable(getResources(), bitmap);
}
});
图像显示为 [OBJ] 而不是图像
解决方案
推荐阅读
- ios - UIView 过渡和 DispatchQueue.main.async 计时问题(在 tableViewController 中)
- speech-recognition - 在 SRGS 语法中,如何指定将短语替换为单词
- html - Flex 页眉、内容、页脚布局
- wcf - 在同一台机器上服务时,UWP 应用程序不连接到 WCF 服务
- java - 重置后,以不同方式声明和初始化的持久数组会发生什么?
- apache-camel - 连接两个数据库的骆驼路线
- regex - 长时间无效输入崩溃 - 角度表单验证
- asynchronous - Clojure - 永久运行的应用程序?
- html - Django 不使用 CSS 读取我的 HTML
- java - 尝试使用命令提示符执行 TestNG 测试时出现配置失败