1

다음은 주어진 이미지의 축소판을 얻기위한 코드입니다. 현재로서는 예외적으로 '커서가 범위를 벗어났습니다.'ContentResolver 및 커서를 사용하여 android에서 이미지의 축소판 가져 오기

어디서나 이미지 URL을 추가하지 않기 때문일 수 있습니다. 나는 그것을하기 위해 어디에서 쯤은 혼란 스럽다. 그래서이 질문 : 나는 열 이름을 인쇄하도록되어 루프 썸네일 2를 획득 할의 나는 이미지 URL을 사용합니까 1. 첫 번째 문 '열 이름'

제외하고는 아무 것도 인쇄합니다

 //get the corresponding thumbnail 
       String lastImageTakenPath = MyActivity.this.savedInstanceStateVariable.getString("lastImageTaken"); 
       System.out.println("previous image is "+ lastImageTakenPath);     

     ContentResolver cr = getContentResolver(); 
     if(cr != null){ 


     String[] projection = { MediaStore.Images.Media._ID }; 

        Cursor cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,projection,null,null,null); 



     //Cursor cursor = cr.query(lastImageTakenURI, null, null, null, null); 
     //Activity.startManagingCursor(cursor); 
     if(cursor != null){ 
     String[] columnNames = cursor.getColumnNames(); 

         System.out.println("COLUMN NAMES"); 
     for(int i=0;i<columnNames.length; i++){ 
      System.out.println(columnNames[i]); 
     } 


      /* 1. get the id of the image 
       * 2. use this id in the call, getThumbnails on MediaStore.Images.Thumbnails to obtain the 
          thumbnail 
     3.set the imageview's src to this thumbnail */ 

     int imageID = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media._ID)); 

     Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID)); 
         // Get original image ID 
         String url = uri.toString(); 
         int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length())); 
     // Get (or create upon demand) the micro thumbnail for the original image.  
      thumbnailLastImage = MediaStore.Images.Thumbnails.getThumbnail(cr, originalImageId, MediaStore.Images.Thumbnails.MICRO_KIND,null); 

     thumbnailImage.setImageBitmap(thumbnailLastImage); 



      } 
      else{ 
      System.out.println("Cursor is NULL"); 
      } 
    } 
    else{ 
     Log.d(TAG,"ContentResolver is NULL"); 
    } 

+0

managedQuery()에있는 URI가 MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI 대신 MediaStore.Images.Media.EXTERNAL_CONTENT_URI와 같아야한다고 생각합니다. – Vamsi

답변

-2

if (cursor! = null) 테스트가 올바르지 않거나 불충분하다고 생각합니다. 쿼리의 결과가 축소판을 반환하지 않으면 커서가 여전히 cursor.getCount() == 0이 될 것입니다.이 경우 커서를 테스트로 사용할 수 있습니다.