因此,无论我做什么,毕加索和滑翔都不能将图像文件或图像字符串路径加载到图像视图中。如何使用picasso和glide加载图像字符串路径和图像文件?
我试过了。
这里是我的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data)
{
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};//Array size of 1, and we put in a string
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
user_image_path = cursor.getString(columnIndex);//here we have our image path.
cursor.close();
File tempFile2 = new File(selectedImage.getPath());
//Toast.makeText(this, "I got your image " + user_image_path, Toast.LENGTH_SHORT).show();
myImageView = (ImageView) findViewById(R.id.cameraActivity_ImageView);
//Picasso.with(TakePhotoActivity.this).load(selectedImage).fit().centerCrop().into(myImageView);
Glide.with(this).load(new File(selectedImage.getPath())).centerCrop().into(myImageView);
}
}
所以我已经试过:
1)Picasso.with(TakePhotoActivity.this).load(user_image_path).fit().centerCrop().into(myImageView);
2)Glide.with(this).load(user_image_path).centerCrop().into(myImageView);
3)Picasso.with(TakePhotoActivity.this).load(tempFile2).fit().centerCrop().into(myImageView);
4)Glide.with(this).load(tempFile2).centerCrop().into(myImageView);
5)Picasso.with(TakePhotoActivity.this).load(selectedImage.getPath())).fit().centerCrop().into(myImageView);
6)Glide.with(this).load(selectedImage.getPath())).centerCrop().into(myImageView);
他们都不工作。如果我使用:
Picasso.with(TakePhotoActivity.this).load(selectedImage).fit().centerCrop().into(myImageView);
Glide.with(this).load(selectedImage).centerCrop().into(myImageView);
上面这两个与Uri selectedImage变量一起工作,但其他都不起作用。那么为什么其他选项不能正常工作,我如何让它们工作,因为理想情况下我想使用图像路径字符串。
希望你们能帮忙!即时通讯完全难住这一个。
这并不工作,并不停地说 “包URI以将String.valueOf()” – TheQ
试试这个Picasso.with(上下文).load(data.getData())到(ImageView的)。 – Diveno
是的data.getData()的作品,但它的作用相同: Picasso.with(TakePhotoActivity.this).load(selectedImage).fit()。centerCrop()。into(myImageView); 我想知道如何使用字符串路径或文件对象与毕加索或滑行 – TheQ