Android 获取联系人列表图像[避免OutOfMemory异常]

Android 获取联系人列表图像[避免OutOfMemory异常],android,bitmap,uri,universal-image-loader,Android,Bitmap,Uri,Universal Image Loader,我需要在应用程序的列表视图中显示所有联系人: 但在使用以下代码显示联系人图像时: viewholder.imageView.setImageBitmap(MediaStore.Images.Media.getBitmap(activity .getContentResolver(), Uri.parse(currentItem.getContactImage()))); 即在内存中获取位图 当我滚动列表视图时,GC被多次调用,我担心在这种情况下会出现Ou

我需要在应用程序的列表视图中显示所有联系人:

但在使用以下代码显示联系人图像时:

viewholder.imageView.setImageBitmap(MediaStore.Images.Media.getBitmap(activity
                    .getContentResolver(), Uri.parse(currentItem.getContactImage())));
即在内存中获取位图

当我滚动列表视图时,GC被多次调用,我担心在这种情况下会出现OutOfMemory异常

这方面的替代方法是什么。 我希望避免将图像作为位图存储在内存中

使用UniversalImageLoader会有帮助吗

请帮忙


提前感谢。

我很久以前从stack中获得了这段代码,现在找不到源代码,但有助于从联系人列表中获取图像,只需将电话号码作为参数传递即可

public Bitmap getFacebookPhoto(String phoneNumber) {
        Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
        Uri photoUri = null;
        ContentResolver cr = _context.getContentResolver();
        Cursor contact = cr.query(phoneUri,
                new String[] { ContactsContract.Contacts._ID }, null, null, null);

        if (contact.moveToFirst()) {
            long userId = contact.getLong(contact.getColumnIndex(ContactsContract.Contacts._ID));
            photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, userId);

        }
        else {
            Bitmap defaultPhoto = BitmapFactory.decodeResource(_context.getResources(), android.R.drawable.ic_menu_report_image);
            return defaultPhoto;
        }
        if (photoUri != null) {
            InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(
                    cr, photoUri);
            if (input != null) {
                return BitmapFactory.decodeStream(input);
            }
        } else {
            Bitmap defaultPhoto = BitmapFactory.decodeResource(_context.getResources(), android.R.drawable.ic_menu_report_image);
            return defaultPhoto;
        }
        Bitmap defaultPhoto = BitmapFactory.decodeResource(_context.getResources(), android.R.drawable.ic_menu_report_image);
        return defaultPhoto;
    }

是否要在ListView中显示手机联系人列表中的图像是的,但不在MemoryTanks中获取位图,但此代码获取内存中的位图。这将导致失去记忆,联系人名单非常庞大。我需要使用联系人列表照片uri显示图像。