Android Glide从网络加载图片 点击可放大查看效果

前言

通过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());
        }
    }
相关推荐
m0_738120722 小时前
PHP代码审计基础——面向对象(四)
android·开发语言·网络·安全·github·php
Coffeeee4 小时前
搞Android的怎么可能搞不懂Context Engineering?
android·人工智能·ai编程
Carson带你学Android4 小时前
Gemini Nano 开发实战:让你的App轻松拥有端侧 AI 功能
android·ai编程
TDengine (老段)5 小时前
TDengine SMA 索引 — 块级/文件级统计索引
android·大数据·服务器·数据库·人工智能·时序数据库·tdengine
心中有国也有家5 小时前
AtomGit Flutter 鸿蒙客户端: AnimatedScale 与 AnimatedContainer 联合实战
android·javascript·flutter·华为·harmonyos
恋猫de小郭6 小时前
Flutter Windows 开始支持 Impeller ,还修复了多窗口 bug
android·前端·flutter
鱼儿也有烦恼7 小时前
07.RecyclerView、SwipeRefreshLayout、SmartRefreshLayout
android
三少爷的鞋7 小时前
Kotlin Flow 深入解析:`stateIn()` 的真正核心,其实是 SharingStarted
android
心中有国也有家19 小时前
AtomGit Flutter 鸿蒙客户端:ModalBottomSheet 实战
android·javascript·学习·flutter·华为·harmonyos
YSoup21 小时前
Android Stuidio中下载TRAE插件依赖的JCEF后打不开
android