Iva*_*vic 4 android image file bitmap picasso
我将一些JPEG图像保存到手机存储器中,我想将使用的毕加索加载到ImageView中.我遇到了麻烦,无论我尝试什么,我只是无法加载图像,ImageView最终都是空白.
以下是我保存和检索图像的方法:
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;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,返回的图像是位图,如何使用picasso将其加载到imageview中?我知道我可以将位图加载到这样的图像中:
imageView.setImageBitmap(getSavedImage(this,user.username+"_Profile"));
但我有一个使用毕加索的课程使用图片(用户个人资料照片),所以我需要用毕加索加载它.
roo*_*dev 17
首先,获取要加载的图像的路径.然后,你可以使用
Picasso.with(context).load(new File(path)).into(imageView);
Run Code Online (Sandbox Code Playgroud)
将图像加载到ImageView中.