【问题标题】:How to display an image capture by camera with original size?如何以原始尺寸显示相机捕获的图像?
【发布时间】:2012-10-07 14:27:21
【问题描述】:

我正在尝试实现一个应用程序,该应用程序将使用相机捕获图像并将其显示在 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。

有人知道怎么解决吗?? 非常感谢。

【问题讨论】:

标签: android image opencv camera


【解决方案1】:

来自ACTION_IMAGE_CAPTURE的官方文档:

调用者可能会传递一个额外的 EXTRA_OUTPUT 来控制此图像的位置 将被写入。如果 EXTRA_OUTPUT 不存在,那么一个小的 大小的图像作为额外字段中的位图对象返回。这是 对于只需要小图像的应用程序很有用。如果 EXTRA_OUTPUT 存在,则全尺寸图像将被写入 EXTRA_OUTPUT 的 Uri 值。

【讨论】:

    【解决方案2】:

    试试这个:-

    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);
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 是的,我试过了。但这取决于图像本身的大小,从相机加载的图像会自动缩小,所以仍然会显示缩小的图像而不是完整的图像。
      猜你喜欢
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 2015-09-12
      • 2019-02-02
      • 2020-04-19
      相关资源
      最近更新 更多