如何提高使用CameraManager拍摄的照片质量

6
比较很简单:我使用 CameraManager 拍摄自定义照片,然后使用默认的 Galaxy Note 5 相机拍摄同样的照片。CameraManager 最大可用尺寸为3264 x 1836,因此我使用该分辨率并将三星相机设置为相同的分辨率。结果如下:
  • Note 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 - Nouvel Travay
你是否正在使用老旧的 android.hardware.Camera 类? - nandsito
抱歉耽搁了。我正在使用 android.hardware.camera2 - Nouvel Travay
啊,当然,CameraManager是camera2。抱歉,我不熟悉这个API。 - nandsito
你看到了哪些质量问题? 你的应用程序中获取的图像是否模糊或至少不够清晰,颜色是否不同,动态范围是否差,是否看到了压缩伪影?建议将严重取决于您观察到的图像质量问题的确切类型。 - Eddy Talvala
2个回答

1
这是一些在相机管理工作中可能有用的方法。
Android相机应用程序将照片编码为小位图,并在Intent中传递到onActivityResult()中,在额外信息下的"data"键下。以下代码检索此图像并在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);
}

0

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接