2015-10-18 44 views
1

我從MediaStore.Images.Thumbnails.getThumbnail(請參見下文)中偶然發現(非常罕見)異常。建議類似的問題總是關閉遊標,但我沒有執行明確的查詢。來自MediaStore.Images.Thumbnails.get的CursorWindowAllocationException異常Thumbnail

我這樣稱呼它:

私有函數讀取的縮略圖。(

 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

你可以添加與此相關的整個代碼嗎? – dex

+0

@dex謝謝你看看.. –

回答

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 
+0

我想驗證這相當於調用getThumbnail方法,但它似乎在某些照片上,遊標返回空。調查.. –

+0

你是否也可以分享這些情況,因爲我無法在我的結尾重新制作它們。 – dex

+0

我無法向您發送有問題的圖像。我所做的是檢查cursor.getCount是否爲0,我違背舊通話。對於某些圖像,當getThumbnail可以時,光標不能讀取縮略圖。 –