问题
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