【问题标题】:Android - Get contact full-size imageAndroid - 获取联系人全尺寸图片
【发布时间】:2013-08-23 12:28:08
【问题描述】:

我正在尝试在给定联系人 ID 的情况下获取联系人的全尺寸图片,我想出了这个:

private Bitmap getUserPhoto(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 BitmapFactory.decodeStream(fd.createInputStream());
    } catch (IOException e) {
        return null;
    }
}

但图片尺寸太小(缩略图)

如何获取联系人的全尺寸照片?

谢谢

【问题讨论】:

  • 当您从联系人获取图像时,它将是缩略图......
  • 是的,我在那里写的,我需要的是全尺寸图像而不是缩略图,Yume 那里的所有解决方案也都返回缩略图

标签: android android-image


【解决方案1】:

如果您的手机中有原始图像,您可以使用openContactPhotoInputStream(ContentResolver cr, Uri contactUri, boolean preferHighres)。并将 preferHighres 设置为 TRUE。

【讨论】:

    【解决方案2】:

    您可以调整大小位图

    private Bitmap getUserPhoto(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 Bitmap.createScaledBitmap(BitmapFactory.decodeStream(fd.createInputStream()), newWidth, newHeight, true);
        } catch (IOException e) {
            return null;
        }
    }    
    

    newWidth 和 newHeight 是 Int 值。

    【讨论】:

    • 否则你可以使用 CONTENT_MAX_DIMENSIONS_URI 而不是 CONTENT_URI 像这样:'ContentUris.withAppendedId(Contacts.CONTENT_MAX_DIMENSIONS_URI, contactId);'
    • 通讯录中没有字段 CONTENT_MAX_DIMENSIONS_URI,它确实存在于 DisplayPhoto 中,无论如何这对我没有帮助,因为它需要 min api 14,无论如何谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2014-01-19
    • 2016-06-08
    • 2015-03-13
    • 2015-05-29
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多