2017-05-27 854 views
0

你好我加載於Android MediaStore電網相似圖片加載圖像失敗,畢加索在Android 7.1

private ArrayList<ImageItem> loadImageData() { 
    Cursor cursor; 
    int columnIndex; 

    // Set up an array of the Thumbnail Image ID column we want 
    String[] projection = {MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Thumbnails._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Thumbnails.DATA}; 

    // Create the cursor pointing to the SDCard 

    cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
      projection, // Which columns to return 
      null,  // Return all rows 
      null, 
      null); 
    // Get the column index of the Thumbnails Image ID 
    int imageID; 

    cursor.moveToFirst(); 
    final ArrayList<ImageItem> imageItems = new ArrayList<>(); 
    for (int i = 0; i < cursor.getCount(); i++) { 
     columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID); 
     imageID = cursor.getInt(columnIndex); 
     int nameIndex = cursor 
       .getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME); 
     int fullImageIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     String uri = "file://" + cursor.getString(fullImageIndex); 


     int thumbIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA); 
     String TbUri = "file://" + cursor.getString(thumbIndex); 



     imageItems.add(new ImageItem(TbUri, cursor.getString(nameIndex), uri)); 
     cursor.moveToNext(); 
     } 

    cursor.close(); 
    return imageItems; 
} 

然後我的拇指添加到電網

 Picasso.with(gridContext).load(item.getImage()).fit().centerCrop().into(Holder.image); 

上的Android 4.0 .1設備這個代碼工作正常。

但在android 7.1上,我得到一些圖像加載到網格,其餘的缺失。不顯示的圖像是使用設備相機拍攝的JPEG圖像。來自下載文件夾或whatsApp的圖像顯示正確。

在logcat中,我得到以下錯誤:

e: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface. java.io.IOException: Invalid marker: 89

可這涉及到縮略圖?因爲我使用:

int thumbIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA); 
    String TbUri = "file://" + cursor.getString(thumbIndex); 
+0

id沒有幫助將其更改爲MediaStore.Images.DATA – wpj

+0

似乎與畢加索有關。因爲ImageView.setImageUri(()直接沒有畢加索它可以工作,但Ofcourse使用太多的資源,這就是爲什麼我首先使用畢加索。 – wpj

回答

0

降級到畢加索版本2.4.0似乎解決了這個問題。也可能與設備有關。我的設備是onePlus 3 7.1.1希望這可以幫助別人。