我获取了照片,但它不好看,它被拉伸了。我通过下面的代码来获取联系人资料图片。请看下面的图片。
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;
}
}