我从MediaStore.Images.Thumbnails.getThumbnail获得偶尔(非常罕见)的异常(见下文)。建议类似的问题始终关闭光标,但我没有执行显式查询。
我称之为:
读取缩略图的私人函数..(
private Bitmap getThumbnail(long imageId) { return MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), imageId,
MediaStore.Images.Thumbnails.MINI_KIND, null); }
从这里调用:
Cursor cursor = null;
int numProcessed = 0, numFaceDetected = 0;
try {
dirtyFile.createNewFile();
String[] projection = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.ORIENTATION
};
cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Images.Media.DATE_ADDED + " desc");
if (cursor == null) {
return;
}
cursor.moveToFirst();
final int columnIndexId = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
final int columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
final int columnIndexOrientation = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.ORIENTATION);
final int columnIndexBucketName = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
while (!cursor.isAfterLast()) {
final long imageId = cursor.getLong(columnIndexId);
final String imagePath = cursor.getString(columnIndexData);
final int imageOrientation = cursor.getInt(columnIndexOrientation);
Bitmap bitmap = getThumbnail(imageId);
faceDetect(bitmap);
cursor.moveToNext();
numProcessed++;
}
以下是例外:
android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
at android.database.CursorWindow.(CursorWindow.java:137)
at android.database.CursorWindow.(CursorWindow.java:42)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:30)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
at android.content.ContentResolver.query(ContentResolver.java:478)
at android.content.ContentResolver.query(ContentResolver.java:422)
at android.provider.MediaStore$InternalThumbnails.getThumbnail(MediaStore.java:680)
at android.provider.MediaStore$Images$Thumbnails.getThumbnail(MediaStore.java:1060)
答案 0 :(得分:0)
Could you try replacing your thumb nail code with this
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 ) );
}
Reference of this answer is taken from [here][1]
[1]: http://stackoverflow.com/questions/5548645/get-thumbnail-uri-path-of-the-image-stored-in-sd-card-android