【问题标题】:Contact Image -Less resolution in android联系人图像-Android中的分辨率较低
【发布时间】:2013-04-10 04:23:56
【问题描述】:

我已检索到 android 手机联系人图像并将其存储在 arraylist 中,如下所示。

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% 质量的联系人图片?

【问题讨论】:

    标签: android image resolution android-contacts


    【解决方案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";
    

    【讨论】:

    • 感谢您的回复。能否请您发布代码以获取联系人图片的 URI。?
    猜你喜欢
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 2011-04-07
    • 2014-11-22
    相关资源
    最近更新 更多