前言
通过url来获取bitmap 然后通过glide工具来加载bitmap 来实现图片点击放大
废话不多说,直接上代码
代码
java
String netPhoto = "xxx";
//从网络加载缓存
try {
Glide.with(TakePhotoSurveyActivity.this).asBitmap().load(photoDesign)
.into(new CustomTarget<Bitmap>() {
@SuppressLint("ClickableViewAccessibility")
@Override
public void onResourceReady(@NonNull Bitmap resource,
@Nullable Transition<? super Bitmap> transition) {
runOnUiThread(() -> bigImageLoaderLocal(resource));
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
点击放大图片
java
/**
* 点击放大本地图片
*
* @param bitmap bitmap
*/
private void bigImageLoaderLocal(Bitmap bitmap) {
Dialog dialog = new Dialog(this);
ImageView image = new ImageView(this);
image.setImageBitmap(bitmap);
dialog.setContentView(image);
//将dialog周围的白块设置为透明
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawableResource
(android.R.color.transparent);
//显示
dialog.show();
//点击图片取消
image.setOnClickListener(v -> dialog.cancel());
}
}