2012-07-20 50 views
0

我面臨從android相機拍照並將其展示給下一活動的問題。過程正常工作,但出了10張照片1張照片被遺漏。延遲和缺失從相機拍攝照片後出現圖片問題

步驟:活動a我調用攝像頭並拍攝圖片,然後我傳遞給它的URI的活動b以在圖像視圖中顯示,重複此循環10次1-2次圖片被錯過,觀察延遲時間爲2秒以黑屏的形式拍攝並在下一個屏幕上顯示圖像視圖。

請檢查代碼並指導我在這裏做什麼錯誤?

活動A

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if(requestCode==CAMERA_IMAGE_CAPTURE && resultCode==Activity.RESULT_OK){ 

     String[] projection = { 
     MediaStore.Images.Thumbnails._ID, // The columns we want 
     MediaStore.Images.Thumbnails.IMAGE_ID, 
     MediaStore.Images.Thumbnails.KIND, 
     MediaStore.Images.Thumbnails.DATA}; 
     String selection = MediaStore.Images.Thumbnails.KIND + "=" + // Select only mini's 
     MediaStore.Images.Thumbnails.MINI_KIND; 

     String sort = MediaStore.Images.Thumbnails._ID + " DESC"; 

     //At the moment, this is a bit of a hack, as I'm returning ALL images, and just taking the latest one. There is a better way to narrow this down I think with a WHERE clause which is currently the selection variable 
     Cursor myCursor = this.getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, selection, null, sort); 

     long imageId = 0l; 
     long thumbnailImageId = 0l; 
     String thumbnailPath = ""; 

     try{ 
     myCursor.moveToFirst(); 
     imageId = myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID)); 
     thumbnailImageId = myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID)); 
     thumbnailPath = myCursor.getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA)); 
     } 
     finally{myCursor.close();} 

     //Create new Cursor to obtain the file Path for the large image 

     String[] largeFileProjection = { 
     MediaStore.Images.ImageColumns._ID, 
     MediaStore.Images.ImageColumns.DATA 
     }; 

     String largeFileSort = MediaStore.Images.ImageColumns._ID + " DESC"; 
     myCursor = this.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, largeFileProjection, null, null, largeFileSort); 
     String largeImagePath = ""; 

     try{ 
     myCursor.moveToFirst(); 

     //This will actually give you the file path location of the image. 
     largeImagePath = myCursor.getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA)); 
     } 
     finally{myCursor.close();} 
     // These are the two URI's you'll be interested in. They give you a handle to the actual images 
     Uri uriLargeImage = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(imageId)); 
     Uri uriThumbnailImage = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, String.valueOf(thumbnailImageId)); 

     Intent next= new Intent(this,AddListing.class); 

     next.putExtra("imageUriThumb", uriThumbnailImage.toString()); 
     next.putExtra("imageUriFull", uriLargeImage.toString()); 

     startActivity(next); 

    } 

    } 

活動B

String uri = bundle.getString("imageUriThumb"); 
      Uri myThumbUri = Uri.parse(uri); 

      try { 
       tempBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),myThumbUri); 
       imgThumbnail.setImageBitmap(tempBitmap); 

       ByteArrayOutputStream bao = new ByteArrayOutputStream(); 
       tempBitmap.compress(Bitmap.CompressFormat.PNG, 90, bao); 

       byte [] ba = bao.toByteArray(); 
       imageBytesString = Base64.encodeToString(ba, 0); 

      } catch (Exception e) { 

      } 
+0

你在哪個設備上測試? – 2012-07-20 11:07:37

+0

三星銀河手機 – UMAR 2012-07-20 11:23:28

+1

ASIAK那裏在使用本機應用程序捕捉圖像時它會遇到一些問題,並且它不會將URI返回到捕獲的圖像。您是否可以在Internet上搜索相同的問題 – 2012-07-20 11:33:22

回答

0

我結束了這個問題,以下幾點:

...我已經尋找這個問題的互聯網上已經實際上這些手機不要使用intent.get(「數據」)獲得圖像,這就是爲什麼我使用以上mentio ned技術。我曾嘗試使用三星王牌手機,三星Galaxy和同樣的問題在那裏。我猜整個三星不工作完美,延遲的反應是有,當你有要求一次又一次地拍照:(其餘的手機像HTC作品完美