未剪切的联系人照片

时间:2012-05-26 21:30:15

标签: android

我想将未剪切的联系人图片照片设置为Android 2.0以上的全屏图像背景。我使用以下代码来获取裁剪的缩略图,但由于照片在画廊中是全屏的,我如何才能访问此照片

此代码提供裁剪的缩略图,如何获取未剪切的全屏

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

1 个答案:

答案 0 :(得分:1)

Android文档说

  

包含该联系人的单个联系人的只读子目录   联系人的主要照片。照片最多可以存储两种方式 -   默认的“照片”是直接存储在缩略图中的图像   数据行,而“显示照片”,,如果存在,则更大   版本存储为文件。

再次来自文档

public InputStream openDisplayPhoto(long contactId) {
     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
     Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
     try {
         AssetFileDescriptor fd =
             getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
         return fd.createInputStream();
     } catch (IOException e) {
         return null;
     }
 }