2016-05-31 63 views
0

因此,無論我做什麼,畢加索和滑翔都不能將圖像文件或圖像字符串路徑加載到圖像視圖中。如何使用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變量一起工作,但其他都不起作用。那麼爲什麼其他選項不能正常工作,我如何讓它們工作,因爲理想情況下我想使用圖像路徑字符串。

希望你們能幫忙!即時通訊完全難住這一個。

回答

0
Picasso.with(context).load(data.getData()).into(imageView); 
+0

這並不工作,並不停地說 「包URI以將String.valueOf()」 – TheQ

+0

試試這個Picasso.with(上下文).load(data.getData())到(ImageView的)。 – Diveno

+0

是的data.getData()的作品,但它的作用相同: Picasso.with(TakePhotoActivity.this).load(selectedImage).fit()。centerCrop()。into(myImageView); 我想知道如何使用字符串路徑或文件對象與畢加索或滑行 – TheQ

0

滑行可以通過Uri完成,如下面的代碼所述。 但你應該檢查

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 

,如果你已經做到了,我不知道。

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode == RESULT_OK){ 
     if (requestCode == PIC_REQ_CODE){ 
      Glide.with(this).load(data.getData()).into((ImageView)findViewById(R.id.iv_result)); 
     } 
    } 
} 
+0

耶data.getData()的作品,但它一樣: Picasso.with(TakePhotoActivity.this).load(selectedImage) .fit()centerCrop()代入(myImageView)。; 我想知道如何使用字符串路徑或File對象與畢加索或滑行 – TheQ

+0

Glide可以直接使用uri,但畢加索不能。如果你想改變實際部分的uri,請閱讀此鏈接-http://stackoverflow.com/questions/6935497/android-uploading-image –

相關問題