|
|
@@ -0,0 +1,52 @@
|
|
|
+package com.mgtech.base_library.util;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.text.Html;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.bumptech.glide.request.target.SimpleTarget;
|
|
|
+import com.bumptech.glide.request.transition.Transition;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.URL;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ProjectName: BaseLibrary
|
|
|
+ * @Package: com.mgtech.base_library.util
|
|
|
+ * @ClassName: HtmlImageGetterUtil
|
|
|
+ * @Description: html 加载图片
|
|
|
+ * @Author: niusongtao
|
|
|
+ * @CreateDate: 2021/1/11 13:24
|
|
|
+ * @UpdateUser: 更新者:niusongtao
|
|
|
+ * @UpdateDate: 2021/1/11 13:24
|
|
|
+ * @UpdateRemark: 更新说明:
|
|
|
+ * @Version: 1.0
|
|
|
+ */
|
|
|
+public class HtmlImageGetterUtil implements Html.ImageGetter{
|
|
|
+ private Context context;
|
|
|
+ private Drawable drawable;
|
|
|
+
|
|
|
+ public HtmlImageGetterUtil(Context context) {
|
|
|
+ this.context = context;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Drawable getDrawable(String source) {
|
|
|
+
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = (InputStream) new URL(source).getContent();
|
|
|
+ drawable = Drawable.createFromStream(inputStream, "src");
|
|
|
+ drawable.setBounds(0,0,50,50);
|
|
|
+ inputStream.close();
|
|
|
+ return drawable;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|