查看大图兼容 BASE64 编码图片
This commit is contained in:
@ -11,6 +11,8 @@ import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -24,6 +26,7 @@ import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.AppExecutor;
|
||||
import com.gh.common.Base64ImageHolder;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
@ -43,6 +46,7 @@ import com.github.piasy.biv.view.BigImageView;
|
||||
import com.github.piasy.biv.view.FrescoImageViewFactory;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@ -287,15 +291,35 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void loadImage(String url, final BigImageView imageView) {
|
||||
// 添加GIF支持
|
||||
try {
|
||||
if (TextUtils.isEmpty(url)) return;
|
||||
|
||||
if (url.startsWith("data:image/png;base64")) {
|
||||
AppExecutor.getIoExecutor().execute(() -> {
|
||||
String base64String = url.replace("data:image/png;base64", "");
|
||||
try {
|
||||
File imageFile = new File(getCacheDir().getAbsolutePath() + File.separator + System.currentTimeMillis() + ".png");
|
||||
|
||||
byte[] decodedString = Base64.decode(base64String, Base64.DEFAULT);
|
||||
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(imageFile));
|
||||
bos.write(decodedString);
|
||||
bos.flush();
|
||||
bos.close();
|
||||
|
||||
AppExecutor.getUiExecutor().execute(() -> {
|
||||
imageView.setImageViewFactory(new FrescoImageViewFactory());
|
||||
imageView.showImage(Uri.fromFile(imageFile));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 添加GIF支持
|
||||
imageView.setImageViewFactory(new FrescoImageViewFactory());
|
||||
imageView.showImage(Uri.parse(url));
|
||||
} catch (Exception ignored) {
|
||||
// parse Uri 可能会有异常 java.lang.NullPointerException
|
||||
// url 为 null? 暂时不管了,统一捕抓异常
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user