Picasso Load image from filesystem

匿名 (未验证) 提交于 2019-12-03 02:11:02

问题:

Can I use Picasso library to load images from the filesystem?

I'm using startActivityForResult to let the user pick a photo from his gallery, and then want to show the selected image.

I already have working code to get the image filesystem Uri, but can't get the Picasso.load() method to work.

回答1:

Of course you can. Its actually pretty straight forward:

File f = new File("path-to-file/file.png")

or

File f = new File(uri)  Picasso.with(getActivity()).load(f).into(imageView);

also

Picasso.with(getActivity()).load(uri).into(imageView);

works



回答2:

Yes you can.

Try:

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

EDIT

You can also call .load(YOUR_URI) instead as well.



回答3:

Looking in the source code I also discover that you can load the image from filesystem adding file: string prefix to your image path. For example:

file:path/to/your/image

Also, when using startActivityForResult, you will get something like this:

Uri imageContent = data.getData();

Then, you can call Picasso.with(getContext()).load(imageContent.toString).into(imageView); directly without need to create a Cursor and querying for the image path.



回答4:

Try this:

Picasso.with(context) .load("file://"+path) // Add this .config(Bitmap.Config.RGB_565) .fit().centerCrop() .into(imageView);

It work perfect for me.



回答5:

Basically we need three things, Context, and the ImageView Container

Picasso.with(context).load("/files/my_image.jpg").into(myImageView);

but we can make use of more options:

  .resize(20, 20)   .centerCrop()   .placeholder(R.drawable.user_placeholder)   .error(R.drawable.user_placeholder_error)

etc...

more info : http://square.github.io/picasso/



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!