获取存储在SD卡+ Android上的图像的缩略图乌里/路径 [英] Get thumbnail Uri/path of the image stored in sd card + android

查看:174
本文介绍了获取存储在SD卡+ Android上的图像的缩略图乌里/路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SDK版本 - 1.6

我使用下面的意图,开放的Andr​​oid默认的库:

I am using following intent to open android's default gallery:

Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(
                        Intent.createChooser(intent, "Select Picture"), 101);

现在在 onActivityResult ,我能够拿到原始的URI和所选图像的路径,但我不能够得到URI和缩略图的路径选定的图像。

Now in onActivityResult, i am able to get the original Uri and path of the selected image, but i am not able to get the Uri and path of the thumbnail of selected image.

code用于获取原始图像URI和路径:

Code for getting the original image Uri and path:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        try {

            if (requestCode == 101 && data != null) {

                Uri selectedImageUri = data.getData();
                String selectedImagePath = getPath(selectedImageUri);
} else {
                Toast toast = Toast.makeText(this, "No Image is selected.",
                        Toast.LENGTH_LONG);
                toast.show();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

PS:1)我不是找来调整图像这样的<一个href="http://stackoverflow.com/questions/4916159/android-get-thumbnail-of-image-on-sd-card-given-uri-of-original-image">question.我专门找这是由Android操作系统本身产生的缩略图。

PS: 1) i am not looking to resize image like this question. I am specifically looking for the thumbnails which are generated by android OS itself.

2)使用SDK 1.6版所以在 ThumbnailUtils 类不感兴趣。

2) Using SDK version 1.6 so not interested in ThumbnailUtils class.

推荐答案

您可以使用它来得到缩略图:

You can use this to get the thumbnail:

Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(
                             getContentResolver(), selectedImageUri,
                             MediaStore.Images.Thumbnails.MINI_KIND,
                             (BitmapFactory.Options) null );

有两种类型的缩略图:
MINI_KIND:512×384缩略图
MICRO_KIND:96×96缩略图

There are two types of thumbnails available:
MINI_KIND: 512 x 384 thumbnail
MICRO_KIND: 96 x 96 thumbnail

或使用<一个href="http://developer.android.com/reference/android/provider/MediaStore.Images.Thumbnails.html#queryMiniThumbnail%28android.content.ContentResolver,%20long,%20int,%20java.lang.String%5B%5D%29">queryMiniThumbnail具有几乎相同的参数,以获得缩略图的路径

OR use queryMiniThumbnail with almost same parameters to get the path of the thumbnail.

修改

Cursor cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(
                             getContentResolver(), selectedImageUri,
                             MediaStore.Images.Thumbnails.MINI_KIND,
                             null );
if( cursor != null && cursor.getCount() > 0 ) {
     cursor.moveToFirst();//**EDIT**
     String uri = cursor.getString( cursor.getColumnIndex( MediaStore.Images.Thumbnails.DATA ) );
}

心连心!

这篇关于获取存储在SD卡+ Android上的图像的缩略图乌里/路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆