0

So no matter what I do, neither picasso and glide can load an image File OR an image string path into an imageview.

I've tried.

here is my code:

 @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);


        }



    }

So I've tried:

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);

None of them worked. If i use the:

Picasso.with(TakePhotoActivity.this).load(selectedImage).fit().centerCrop().into(myImageView);

Glide.with(this).load(selectedImage).centerCrop().into(myImageView);

These two above work with the Uri selectedImage variable, but none of the others work. So why aren't the other options working and how do I get them to work, because ideally I want to work with image path Strings.

Hope you guys can help! im totally stumped on this one.

TheQ
  • 1,770
  • 6
  • 33
  • 60

2 Answers2

0
Picasso.with(context).load(data.getData()).into(imageView);
Diveno
  • 1,408
  • 1
  • 13
  • 12
  • That didn't work, and it kept saying "wrap uri with String.valueOf()" – TheQ May 31 '16 at 14:24
  • Try this Picasso.with(context).load(data.getData()).into(imageView); – Diveno May 31 '16 at 14:32
  • yeah the data.getData() works, but its the same as: Picasso.with(TakePhotoActivity.this).load(selectedImage).fit().centerCrop().into(myImageView); I want to know how to use a string path or File object with Picasso or glide – TheQ May 31 '16 at 14:43
0

Glide can do via Uri, as the code mention below. But you should check

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

if you already done it, I have no idea.

@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));
        }
    }
}
Ko Nyan
  • 51
  • 1
  • 3
  • yeah the data.getData() works, but its the same as: Picasso.with(TakePhotoActivity.this).load(selectedImage).fit().centerCrop().into(myImageView); I want to know how to use a string path or File object with Picasso or glide – TheQ May 31 '16 at 14:42
  • Glide can use uri directly but picasso cannot. If you want to change uri to actual part please read this link-http://stackoverflow.com/questions/6935497/android-uploading-image – Ko Nyan Jun 02 '16 at 05:31