2012-07-20 110 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作品完美

相关问题