从内部存储加载带有毕加索的图像 [英] Loading Images With Picasso From The Internal Storage

查看:71
本文介绍了从内部存储加载带有毕加索的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些 JPEG 图像保存到手机存储中,我想将 using picasso 加载到 ImageView 中.但是我遇到了问题,无论我尝试什么,我都无法加载图像,ImageView 最终变成空白.

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

如您所见,返回的图像是位图,如何使用 picasso 将其加载到图像视图中?我知道我可以将位图加载到这样的图像中:

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

但是我有一个使用 picasso 对图像(用户个人资料照片)进行四舍五入的类,所以我需要使用 picasso 加载它.

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

推荐答案

首先获取要加载的图片的路径.然后,您可以使用

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

将图像加载到 ImageView 中.

to load the image into an ImageView.

这篇关于从内部存储加载带有毕加索的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆