开发者

android - how to pull images from DCIM/CAMERA by sampling thumbnails

开发者 https://www.devze.com 2023-03-13 05:09 出处:网络
Hi I am trying ot load images stored on the card and figured that its better to load the bitmaps, but I want to have both full path and thumbnail path. How do I do that? I would like my adapter to sho

Hi I am trying ot load images stored on the card and figured that its better to load the bitmaps, but I want to have both full path and thumbnail path. How do I do that? I would like my adapter to show me the list of thumbnails but when I click I need to redirect to a preview so I also need a full path. So if my object is Image, I need to have imagePath and imageThumbPath loaded at the same time.

Here is how I load them now:

new Image(data) where data is the path to the actual image. How do I load thumb path simultaneously into same object?

public static List<Image> getCameraImages(Context context) {
                        final String[] projection = { MediaStore.Images.Media.DATA };
                        final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
                        final String[] selectionArgs = { CAMERA_IMAGE_BUCKET_ID };
                        final Cursor curs开发者_C百科or = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, 
                                projection, 
                                selection, 
                                selectionArgs, 
                                null);
                        List<Image> result = new ArrayList<Image>(cursor.getCount());
                        if (cursor.moveToFirst()) {
                            final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                            do {
                                final String data = cursor.getString(dataColumn);
                                result.add(new Image(data));
                            } while (cursor.moveToNext());
                        }
                        cursor.close();
                        return result;
                    }

    public static final String CAMERA_IMAGE_BUCKET_NAME =
                    Environment.getExternalStorageDirectory().toString()
                    + "/DCIM/Camera";
                public static final String CAMERA_IMAGE_BUCKET_ID = getBucketId(CAMERA_IMAGE_BUCKET_NAME);

    public static String getBucketId(String path) {
                    return String.valueOf(path.toLowerCase().hashCode());
                }


and I found how to do hat ONLY to find out that the thumbs are all same size as originals!!! Horrible!

0

精彩评论

暂无评论...
验证码 换一张
取 消