我从通讯录中获取联系人个人资料图片,但照片总是被拉伸

I fetch contact profile image from contact book but photo is stretched always

我取了照片,但它看起来不太好,它被拉长了。我通过以下代码获取联系人个人资料图片。请找到附件图片。

Bitmap photo = null;
    try {
        InputStream inputStream = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(),
                ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.valueOf(columnIndex)));
        if (inputStream != null) {
            photo = BitmapFactory.decodeStream(inputStream);
            inputStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    //contactIm.setImageBitmap(photo);
    if (photo == null) {
        /*String letter = gc.split_word(cName);
        TextDrawable drawable = gc.name_image(letter);
        contact_image.setImageDrawable(drawable);*/
    } else {
        contactIm.setImageBitmap(photo);
    }

我已经解决了我的问题。

imageView.setImageBitmap(BitmapFactory.decodeStream(openDisplayPhoto(contactId)));

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