chinalwb / Android-Rich-text-Editor

Android Rich Text Editor With customized spans - 富文本编辑器 - Don't miss this one :)
Apache License 2.0
845 stars 167 forks source link

兼容BASE64图片内容 #159

Open RavenGluttonous opened 2 years ago

RavenGluttonous commented 2 years ago

想要兼容BASE64需要改动这两个文件,Html.class,以及AreImageGetter.class。

在AreImageGetter.class文件找到getDrawable(),加入判断: else if (source.startsWith("data:image")){ // data:image/jpg;base64 AreUrlDrawable areUrlDrawable = new AreUrlDrawable(mContext); BitmapTarget bitmapTarget = new BitmapTarget(areUrlDrawable, mTextView); try { //ImageUtil.INSTANCE.str2Bitmap(source); //此方法为转bitmap方法,source为base64字符串 Bitmap s = ImageUtil.INSTANCE.str2Bitmap(source); sGlideRequests.asBitmap().load(s).into(bitmapTarget); return areUrlDrawable; } catch (Exception ignored) { ignored.printStackTrace(); } }

在Html.class文件找到startImg(),加入判断: else if (src.startsWith("data:image")){ imageSpan = new AreImageSpan(sContext, d, src); }