Saving thumbnails to .thumbnails folder

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 06:21:07

问题


Hi I am trying to save an image to the .thumbnails folder as shown below:

bitmap = ThumbnailUtils.extractThumbnail
                                (BitmapFactory.decodeFile(actualImagePath,options), 120, 120);
                                bitmapGenerated = true;
                        File file = new File(Environment.getExternalStorageDirectory()
                                .toString()+"/"+"DCIM/.thumbnails/"+id+".jpg");
                        boolean bcc =file.createNewFile();
                        boolean success = bitmap.compress(Bitmap.CompressFormat.PNG,60,new
                                FileOutputStream
                                (file));

The 'id' is actually the id of the particular image that I am trying to save and is obtained from a cursor as shown:

image_column_index = mCursor.getColumnIndex(MediaStore.Images.Media._ID);
id = mCursor.getLong(image_column_index);

The image gets saved in the '.thumbnails' , however, as I try to access the image thumbnail that I just created, it is not read. I think it was because of the name I gave to the thumbnail image.

So my question is it okay to save to '.thumbnails' folder and if so in what name should we save the file?

Help is really appreciated,

Thank You.


回答1:


I found out that to generate a thumbnail we don't need to explicitly create a thumbnail image file and put it in the .thumbnials folder.

There is a method called getThumbnail in MediaStore.Images.Media that we can use for our purpose. Code is as shown:

    Cursor mCursor;
mCursor = mContext.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null,
                null, null, null);
int image_column_index = mCursor.getColumnIndex(MediaStore.Images.Media._ID);
long id = mCursor.getLong(image_column_index);
MediaStore.Images.Thumbnails.getThumbnail(mContext
                    .getContentResolver(), id, MediaStore.Images.Thumbnails.MINI_KIND, null);

The above code will generate a thumbnail for the associated imageid , first we have to make sure that the thumbnail doesn't exist and create a new one only if one doesn't exist.



来源:https://stackoverflow.com/questions/30527266/saving-thumbnails-to-thumbnails-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!