【问题标题】:File not found exception in setImageURI();在 setImageURI() 中找不到文件异常;
【发布时间】:2012-07-19 08:29:59
【问题描述】:

我正在设置 sd 卡中的联系人图像,并通过我的应用程序尝试在列表适配器中显示它。我能够正确获取图像 uri。但是当我试图设置

img.setImageURI(uri); 

有时我收到文件未找到异常。甚至将 uri 转换为位图时出现问题。我有四个联系人,其中 2 个联系人与图像显示正确,剩下两个我找不到文件异常。请帮助。

【问题讨论】:

  • 尝试使用 img.setImageURI(Uri.Parse("sdcard_image_path"));

标签: android android-imageview android-file


【解决方案1】:

查看此链接 https://stackoverflow.com/a/4240238/1441666

public static Bitmap loadContactPhoto(ContentResolver cr, long  id) {
    Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
    InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
    if (input == null) {
        return null;
    }
    return BitmapFactory.decodeStream(input);
}

【讨论】:

  • 嘿。我正在获取联系人图像 uri,例如“内容:内容://com.android.contacts/contacts/7/photo”。它告诉这个文件没有找到异常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多