Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to load a photo with Picasso

I am implementing an app and i’m trying to load the photo using picasso but i am not getting any result . How can i figure it out ? Here ‘s what i’ve done :

    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);
    
            }
        }
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m not sure about picasso that it shows image from filePath or not. But glide can do that.

Using glide with listener, you can surely achieve image

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading