Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Images With Picasso From The Internal Storage

I saved a few JPEG images into the phones storage and I want to load the using picasso into an ImageView. I'm having trouble with it though, whatever I try I just can't load the image, the ImageView end up being blank.

Here's how I save and retrieve the images:

 private void saveImage(Context context, String name, Bitmap bitmap){
    name=name+".JPG";
    FileOutputStream out;
    try {
        out = context.openFileOutput(name, Context.MODE_PRIVATE);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}


private Bitmap getSavedImage(Context context, String name){
    name=name+".JPG";
    try{
        FileInputStream fis = context.openFileInput(name);
        Bitmap bitmap = BitmapFactory.decodeStream(fis);
        fis.close();
        return bitmap;
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return null;
}

As you can see the returned image is a bitmap, how can I load it into a imageview using picasso? I know I can load the bitmap into an image like this:

imageView.setImageBitmap(getSavedImage(this,user.username+"_Profile"));

But I have a class which using picasso rounds up the image(users profile photo) so I need to load it with picasso.

like image 755
Ivan Javorovic Avatar asked Aug 02 '15 22:08

Ivan Javorovic


People also ask

What is Picasso library in Android?

Picasso allows for hassle-free image loading in your application—often in one line of code! Picasso. get(). load("https://i.imgur.com/DvpvklR.png").into(imageView);

How do you load an image into an imageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.

Which library do we use to display images from Internet in Android?

Glide is an Image Loader Library in Android developed by bumptech and is a library that is backed by Google.


1 Answers

First of all, obtain the path of the image to be loaded. Then, you can use

Picasso.with(context).load(new File(path)).into(imageView);

to load the image into an ImageView.

like image 85
rookiedev Avatar answered Nov 15 '22 16:11

rookiedev