我试图找到如何使用 picasso 库将图像从字节或位图加载到 imageview。
这就是我想做的
ImageView imageview1 = row.FindViewById<ImageView>(Resource.Id.CategoryImageView);
Bitmap decodedByte = BitmapFactory.DecodeByteArray(Image, 0, Image.Length);
Picasso.With(mContext).Load((decodedByte)).Into(imageview1);
但我收到错误无法将 android 图形位图转换为 anroid net uri 这也是我正在尝试的 byte[]
byte[] Image;
Picasso.With(mContext).Load((Image)).Into(imageview1);
现在我收到错误无法将 android 图形字节 [] 转换为 anroid net uri
还有其他方法可以转换吗?
最佳答案
根据我们的消息,我认为使用 Picasso 将位图放入 ImageView 中并不是最适合您的解决方案。
如果您的应用程序的主要问题是由于使用 ListView
显示许多图像列表而导致的性能问题,我建议您改用 RecyclerView
。看official documentation .
如果您仍然想使用 Picasso 将图像放在其 ImageView 上,那么我认为最好不要将它们直接存储在 SQLite
数据库上,而是将它们存储在手机存储上,并将其文件系统完整路径
(例如/storage/yourfolder/image1.png)保存在 SQLite
数据库上。
因此,您可以始终使用 RecyclerView
(由于其内存管理,您始终应该选择显示项目列表的布局),并且在其 ViewHodlder 中您可以使用 Picasso正如 Prafulla Malviya 所说,将图像显示到 ViewHolder ImageViews 从文件系统中获取图像。
如您所知,Picasso 可以显示来自任何资源、 Assets 、文件和内容提供商的图像:
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.with(context).load(new File(...)).into(imageView3);
关于java - Picasso 加载位图或 byte[] 到 imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48967725/