我正在尝试使用以下代码获取缩略图位图,但它失败了,并将错误扔到下面。如何解决此错误?
代码
bitmap = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
// I get id like
String[] projection = new String[]{MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.TITLE,
MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.SIZE,
MediaStore.Images.Media.MIME_TYPE,
MediaStore.Images.Media.DATE_TAKEN};
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,null, MediaStore.Images.Media.DATE_TAKEN + " desc");
id = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID));
错误
E/MiniThumbFile( 6355): miniThumbDataFile: IOException(rw) for: /storage/emulated/0/.thumbnails/.thumbdata-6.0_18, try read only mode
E/MiniThumbFile( 6355): java.io.FileNotFoundException: /storage/emulated/0/.thumbnails/.thumbdata-6.0_18: open failed: EACCES (Permission denied)
E/MiniThumbFile( 6355): at libcore.io.IoBridge.open(IoBridge.java:453)
E/MiniThumbFile( 6355): at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118)
E/MiniThumbFile( 6355): at android.media.MiniThumbFile.miniThumbDataFile(MiniThumbFile.java:174)
E/MiniThumbFile( 6355): at android.media.MiniThumbFile.getMagic(MiniThumbFile.java:211)
E/MiniThumbFile( 6355): at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:653)
E/MiniThumbFile( 6355): at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:1152)
E/MiniThumbFile( 6355): at com.dvlee.androidtest.util.LocalImageBitmapUtil.getThumbnail(LocalImageBitmapUtil.java:140)
E/MiniThumbFile( 6355): at com.dvlee.androidtest.util.BitmapCacheHelper$BitmapWorkerTask.doInBackground(BitmapCacheHelper.java:118)
E/MiniThumbFile( 6355): at com.dvlee.androidtest.util.BitmapCacheHelper$BitmapWorkerTask.doInBackground(BitmapCacheHelper.java:78)
E/MiniThumbFile( 6355): at android.os.AsyncTask$2.call(AsyncTask.java:288)
E/MiniThumbFile( 6355): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/MiniThumbFile( 6355): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
E/MiniThumbFile( 6355): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/MiniThumbFile( 6355): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/MiniThumbFile( 6355): at java.lang.Thread.run(Thread.java:848)
E/MiniThumbFile( 6355): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
E/MiniThumbFile( 6355): at libcore.io.Posix.open(Native Method)
E/MiniThumbFile( 6355): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
E/MiniThumbFile( 6355): at libcore.io.IoBridge.open(IoBridge.java:437)
E/MiniThumbFile( 6355): ... 14 more
E/MiniThumbFile( 6355): Got exception when reading thumbnail, id = 307318, disk full or mount read-only? class java.nio.channels.NonWritableChannelException
E/MiniThumbFile( 6355): miniThumbDataFile: IOException(rw) for: /storage/emulated/0/.thumbnails/.thumbdata-6.0_18, try read only mode
E/MiniThumbFile( 6355): java.io.FileNotFoundException: /storage/emulated/0/.thumbnails/.thumbdata-6.0_18: open failed: EACCES (Permission denied)
E/MiniThumbFile( 6355): at libcore.io.IoBridge.open(IoBridge.java:453)
E/MiniThumbFile( 6355): at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118)
E/MiniThumbFile( 6355): at android.media.MiniThumbFile.miniThumbDataFile(MiniThumbFile.java:174)
E/MiniThumbFile( 6355): at android.media.MiniThumbFile.getMagic(MiniThumbFile.java:211)
E/MiniThumbFile( 6355): at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:653)
E/MiniThumbFile( 6355): at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:1152)
E/MiniThumbFile( 6355): at com.dvlee.androidtest.util.LocalImageBitmapUtil.getThumbnail(LocalImageBitmapUtil.java:140)
E/MiniThumbFile( 6355): at com.dvlee.androidtest.util.BitmapCacheHelper$BitmapWorkerTask.doInBackground(BitmapCacheHelper.java:118)
E/MiniThumbFile( 6355): at com.dvlee.androidtest.util.BitmapCacheHelper$BitmapWorkerTask.doInBackground(BitmapCacheHelper.java:78)
E/MiniThumbFile( 6355): at android.os.AsyncTask$2.call(AsyncTask.java:288)
E/MiniThumbFile( 6355): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/MiniThumbFile( 6355): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
E/MiniThumbFile( 6355): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/MiniThumbFile( 6355): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/MiniThumbFile( 6355): at java.lang.Thread.run(Thread.java:848)
E/MiniThumbFile( 6355): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
E/MiniThumbFile( 6355): at libcore.io.Posix.open(Native Method)
E/MiniThumbFile( 6355): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
E/MiniThumbFile( 6355): at libcore.io.IoBridge.open(IoBridge.java:437)
E/MiniThumbFile( 6355): ... 14 more
E/MiniThumbFile( 6355): Got exception when reading thumbnail, id = 307316, disk full or mount read-only? class java.nio.channels.NonWritableChannelException
答案 0 :(得分:0)
您可以使用ThumbnailUtils。
final int THUMBSIZE = 64;
Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath),
THUMBSIZE, THUMBSIZE);