【问题标题】:How to increase quality of photos taken with CameraManager如何提高使用 CameraManager 拍摄的照片质量
【发布时间】:2016-11-11 20:32:28
【问题描述】:

比较很简单:我使用使用 CameraManager 的自定义相机拍照。然后我使用默认的 Galaxy Note 5 相机拍摄同一张照片。 CameraManager 可用的最大尺寸是3264 by 1836,所以我使用它并将三星相机也设置为相同的分辨率。结果

  • 注 5:我可以在照片中看到详细信息
  • CameraManager:我看不到细节。图片质量很差。

然后我尝试使用

设置 CameraManager 照片
 captureBuilder.set(CaptureRequest.JPEG_QUALITY, (byte) 100);

仍然没有变化。好吧,只有一个变化:使用 CameraManager 拍摄的照片的文件大小变为 2.3MB(以前是 0.5MB),而三星照片的大小(仍然)为 1.6MB。因此,即使尺寸较大,使用 CameraManager 拍摄的照片质量仍然较低。有什么想法可以解决这个问题:如何使使用 CameraManager 拍摄的照片与使用 Note 5 附带的默认相机应用拍摄的照片具有相同的质量?

【问题讨论】:

  • 另外为什么三星相机可以达到5312x2088,而CameraManager报告最大3264 by 1836
  • 你使用的是普通的android.hardware.Camera类吗?
  • 抱歉耽搁了。我正在使用android.hardware.camera2
  • 啊,CameraManager当然是camera2。抱歉,我不熟悉这个 API
  • 您看到什么样的质量问题?您在应用程序中获得的图像是否失焦或至少不那么清晰,颜色是否不同,动态范围是否不好,您是否看到压缩伪影?建议在很大程度上取决于您观察到的图像质量问题类型。

标签: android android-camera


【解决方案1】:

这些是我们在Camer manager工作时的一些方法,这个方法 可以帮到你。

Android 相机应用程序在 Intent 中对照片进行编码 交付给 onActivityResult() 作为额外内容中的一个小位图,在 关键的“数据”。以下代码检索此图像并显示 它在 ImageView 中。

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            mImageView.setImageBitmap(imageBitmap);
        }
    }
    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
        mCurrentPhotoPath = "file:" + image.getAbsolutePath();
        return image;
    }
private void setPic() {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW/targetW, photoH/targetH);

    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    mImageView.setImageBitmap(bitmap);
}

【讨论】:

    【解决方案2】:

    我认为三星相机应用程序的质量更好,因为它使用Samsung Camera SDK。它是 Camera2 API 的扩展。

    SDK 提供有用的附加功能(例如相位自动对焦)。尝试同时启用镜头光学稳定功能。

    【讨论】:

      猜你喜欢
      • 2019-04-16
      • 1970-01-01
      • 2011-10-18
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多