因此,無論我做什麼,畢加索和滑翔都不能將圖像文件或圖像字符串路徑加載到圖像視圖中。如何使用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