【问题标题】:How to load a photo with Picasso如何使用 Picasso 加载照片
【发布时间】:2023-01-17 23:15:24
【问题描述】:

我正在实施一个应用程序,我正在尝试使用 picasso 加载照片,但我没有得到任何结果。我怎样才能弄清楚?这是我所做的:

    public class FullScreenPhoto extends AppCompatActivity {
    ActivityFullScreenPhotoBinding binding;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            binding=ActivityFullScreenPhotoBinding.inflate(getLayoutInflater());
            setContentView(binding.getRoot());
    //Retrieving image path
            Intent intent = getIntent();
            String path =intent.getStringExtra("image_path");
//value of path=/storage/emulated/0/Android/data/com.ticanalyse.mheath.bf/files/Pictures/AH144644_7972289747179568715.jpg
            if (Objects.equals(path, "no_image")) {
                binding.imageContainer.setVisibility(View.GONE);
                binding.textView.setVisibility(View.VISIBLE);
            }else{
                Log.d("path",path);
                binding.imageContainer.setVisibility(View.VISIBLE);
                Picasso.get()
                        .load(path)
                        .into(binding.imageContainer);
    
            }
        }
    }

【问题讨论】:

  • 您是否尝试过添加一个侦听器来侦听错误消息?
  • 我通常检查 logcat 是否有错误。但是没有错误显示,我的应用程序也没有崩溃。我只是尝试使用 Picasso 加载图像,但图像不显示

标签: java android picasso android-camera2 android-camera-intent


【解决方案1】:

我不确定 picasso 是否显示来自 filePath 的图像。但是滑行可以做到这一点。

使用glide with listener,你一定可以实现图像

Glide
    .with(context)
    .load(path)
    .listener(object : RequestListener<Drawable> {
        override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
            //TODO handle error images while loading photo
            return true
        }

        override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
            //TODO use "resource" as the photo for your ImageView
            return true
        }

    })
    .into(binding.imageContainer)

【讨论】:

    猜你喜欢
    • 2014-07-27
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多