Am trying to fetch phone contacts image and set into an ImageView . Am getting the image, but when I try to set the image into an ImageView it is pixelated.
The code for fetching the image
String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" + name + "\" )";
Cursor c = getApplicationContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
startManagingCursor(c);
if (c.moveToNext()) {
idValue = c.getString(0);
InputStream inputStream = ContactsContract.Contacts.openContactPhotoInputStream(getApplicationContext().getContentResolver(),
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(idValue)));
if (inputStream != null) {
photo = BitmapFactory.decodeStream(inputStream);
contact_image.setImageBitmap(photo);
}
}
I want to show the details of contacts , Because of that i try fetch the Contact ID by name.
Layout.xml
<ImageView
android:id="@+id/contact_image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="@drawable/un_known_avtar" />
I try almost all scale type by xml. But still the contact image is stretchered.
Can any one please help to avoid the stretching of Contact Image
try adding true boolean at end of openContactPhotoInputStream
for high resolution (NEEDS API LEVEL 14 OR HIGHER)
InputStream inputStream = ContactsContract.Contacts.openContactPhotoInputStream(getApplicationContext().getContentResolver(),
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(idValue)), true);