2012-10-17 137 views
1

我想实现一个应用程序,该应用程序将使用相机捕获图像并将其显示在ImageView上。但是,系统会将图像分辨率调整为204x153,然后将其显示在屏幕上,但它会将图像的原始分辨率(3264x2448)保存在SD卡中。如何显示原始尺寸的相机拍摄图像?

这是我的代码。

buttonCapture.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      Intent intentCamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      bmpUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), 
        "pic_" + String.valueOf(System.currentTimeMillis()) + ".jpg")); 
      try { 
       intentCamera.putExtra("return-data", false); 
       startActivityForResult(intentCamera, resultOpenCamera); 
      } 
      catch (ActivityNotFoundException e) { 
       e.printStackTrace(); 
      }    
     } 
    }); 

和我的onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     if (requestCode == resultOpenCamera && resultCode == RESULT_OK && null != data) { 
      setContentView(R.layout.preview); 

      if(data.getAction() != null){ 

       Uri selectedImage = data.getData(); 
       bmpUri = selectedImage; 
       // display image received on the view 
       Bundle newBundle = data.getExtras(); 
       Bitmap theImage = (Bitmap) newBundle.get("data"); 
       displayImage(preProcessing(theImage)); 
       System.out.println("theImage height n width = "+theImage.getHeight()+" + "+theImage.getWidth()); 
      } 
     } 
} 

我使用的System.out.println跟踪位图分辨率从摄像机捕获。它表明只有204x153。原始分辨率应该是3264x2448。

任何人都知道如何解决这个问题? 非常感谢。

+0

请参考这个问题。它与此相似。 http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – Scorpion

回答

2

单从ACTION_IMAGE_CAPTURE官方文档:

调用者可以通过一个额外的EXTRA_OUTPUT为了控制这一形象 将被写入。如果EXTRA_OUTPUT不存在,则在额外字段中将返回一个尺寸较小的图像作为位图对象。这是 对于只需要小图像的应用程序很有用。如果存在 EXTRA_OUTPUT,则全尺寸图像将被写入 EXTRA_OUTPUT的Uri值。

0

尝试将imageview的缩放类型设置为center或centerInside。

+0

是的,我试过这个。但取决于图像本身的大小,从相机加载的图像将自动缩小,因此仍然会显示缩小图像而不是全部图像。 –

0

试试这个: -

int width = bmpSelectedImage.getWidth(); 
int height = bmpSelectedImage.getHeight(); 
float scaleWidth = ((float) 250)/width; 
float scaleHeight = ((float) 150)/height; 
Matrix matrix = new Matrix(); matrix.postRotate(90); 
resizedBitmap = Bitmap.createBitmap(bmpSelectedImage, 0, 0, width, height, matrix, true); 
+0

感谢您回答我的问题。 –

相关问题