2013-04-10 49 views
2

我已经检索了android手机的联系人图片并将其存储在如下所示的arraylist中。联系我们在Android上的低分辨率

id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); 
String photoWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " +ContactsContract.Data.MIMETYPE + " = ?"; 
String[] photoParams = new String[] {id,ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE}; 
Cursor photoCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, null, photoWhere, photoParams, null);      
if(photoCursor!=null && photoCursor.getCount()>0) 
{ 
while(photoCursor.moveToNext()) 
    { 
     byte[] contactPhoto = photoCursor.getBlob(photoCursor.getColumnIndex(ContactsContract.CommonDataKinds.Photo.PHOTO));       
     if(contactPhoto!=null) 
     { 
      mContactImage="data:image/jpeg;base64," + Base64.encodeToString(contactPhoto, Base64.NO_WRAP);     
      sContactImageArray.add(mContactImage); 
     }           
    } 
}         
photoCursor.close(); 

然后,我有此的base64字符串传递到JavaScript和显示为图像。但图像分辨率很差。这与存储在手机联系人中的图像不同。如何以100%质量检索联系人图片?

回答

1

请参考这些区域。看起来,如果联系人头像是从本地照片设置的,您可能有机会获得高分辨率版本。

/** 
    * Reference to the row in the data table holding the photo. A photo can 
    * be referred to either by ID (this field) or by URI (see {@link #PHOTO_THUMBNAIL_URI} 
    * and {@link #PHOTO_URI}). 
    * If PHOTO_ID is null, consult {@link #PHOTO_URI} or {@link #PHOTO_THUMBNAIL_URI}, 
    * which is a more generic mechanism for referencing the contact photo, especially for 
    * contacts returned by non-local directories (see {@link Directory}). 
    * 
    * <P>Type: INTEGER REFERENCES data(_id)</P> 
    */ 
    public static final String PHOTO_ID = "photo_id"; 

    /** 
    * Photo file ID of the full-size photo. If present, this will be used to populate 
    * {@link #PHOTO_URI}. The ID can also be used with 
    * {@link ContactsContract.DisplayPhoto#CONTENT_URI} to create a URI to the photo. 
    * If this is present, {@link #PHOTO_ID} is also guaranteed to be populated. 
    * 
    * <P>Type: INTEGER</P> 
    */ 
    public static final String PHOTO_FILE_ID = "photo_file_id"; 

    /** 
    * A URI that can be used to retrieve the contact's full-size photo. 
    * If PHOTO_FILE_ID is not null, this will be populated with a URI based off 
    * {@link ContactsContract.DisplayPhoto#CONTENT_URI}. Otherwise, this will 
    * be populated with the same value as {@link #PHOTO_THUMBNAIL_URI}. 
    * A photo can be referred to either by a URI (this field) or by ID 
    * (see {@link #PHOTO_ID}). If either PHOTO_FILE_ID or PHOTO_ID is not null, 
    * PHOTO_URI and PHOTO_THUMBNAIL_URI shall not be null (but not necessarily 
    * vice versa). Thus using PHOTO_URI is a more robust method of retrieving 
    * contact photos. 
    * 
    * <P>Type: TEXT</P> 
    */ 
    public static final String PHOTO_URI = "photo_uri"; 

    /** 
    * A URI that can be used to retrieve a thumbnail of the contact's photo. 
    * A photo can be referred to either by a URI (this field or {@link #PHOTO_URI}) 
    * or by ID (see {@link #PHOTO_ID}). If PHOTO_ID is not null, PHOTO_URI and 
    * PHOTO_THUMBNAIL_URI shall not be null (but not necessarily vice versa). 
    * If the content provider does not differentiate between full-size photos 
    * and thumbnail photos, PHOTO_THUMBNAIL_URI and {@link #PHOTO_URI} can contain 
    * the same value, but either both shall be null or both not null. 
    * 
    * <P>Type: TEXT</P> 
    */ 
    public static final String PHOTO_THUMBNAIL_URI = "photo_thumb_uri"; 
+0

Thansks for the response。您可以发布代码来获取联系人图片的URI吗? – Karthick 2013-04-10 04:52:11