2015-12-23 136 views
5

我一直在尝试并搜索过去5个小时的答案。 我正在将图像从谷歌加到本地文件夹,并使用Glide库将图像加载到imageview中。使用Glide从SD卡加载图像

的文件URI是文件:///storage/emulated/0/MyApp/ProfilePics/profile_user1.jpg

我用下面的图像加载代码通过滑行:

Glide.with(ProfileActivity.this).load(Uri.fromFile(new File(sharedPrefMan.getImageUrl()))).placeholder(R.drawable.placeholder_profile).into(imgProfilePic); 

其中sharedPrefMan.getImageUrl()返回/storage/emulated/0/MyApp/ProfilePics/profile_user1.jpg

的图像是存在于给定位置。

+0

你没有指定做了什么,你与这个有问题代码.. ?? – Hardy

回答

0

只需使用以下行: -

Glide.with(context).load(uri).transform(new Transform()).into(view) 

而对于越来越URI使用下面的代码: -

Uri.fromFile(new File(Yourpath)); 
11

如果您有图像的原始路径比你要转换为URI和显示像这样的图像

String fileName = "1.jpg"; 
    String completePath = Environment.getExternalStorageDirectory() + "/" + fileName; 

    File file = new File(completePath); 
    Uri imageUri = Uri.fromFile(file); 

    Glide.with(this) 
      .load(imageUri) 
        .into(imgView); 

好像你有URI比你必须把比URI只有

Glide.with(this) 
      .load(Uri) 
        .into(imgView); 
+0

保存我的时间..谢谢 –

3

你要通过图像URI这样如下:

Glide.with(this) 
       .load(Uri.parse("file:///sdcard/img.png")) 
       .override(612, 816) 
       .into(imageView);