【问题标题】:Why image's resolution from Camera.PictureCallback() is the size of PreviewSize?为什么 Camera.PictureCallback() 的图像分辨率是 PreviewSize 的大小?
【发布时间】:2012-02-06 12:37:38
【问题描述】:

我正在尝试使用 Android Camera API,但是当我拍照时,它的分辨率与我的 Camera 对象 previewSize 分辨率相同。

一些解释代码:

private Camera mCamera;
private Camera.PictureCallback mPictureCallback;

...
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
...
Camera.Parameters p = mCamera.getParameters();
        p.setPreviewSize(mPreviewWidth, mPreviewHeight);
        p.setPictureSize(mPictureWidth,mPictureHeight);
mCamera.setParameters(p);
...
}

public void onPictureTaken(byte[] imageData, Camera c) {
                Bitmap bitmapPicture = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
                bitmapPicture.getWidth(); //At this point the width is the same as mPreviewWidth and I want it to be mPictureWidth
}
/**
* This function is called when the user touches the surfaceview
*/
public void clickCamera(View v){
        mCamera.takePicture(null, mPictureCallback, mPictureCallback);
    }

我在评论行怎么说,而不是 previewSize 我想用配置到我的相机的pictureSize 拍照

【问题讨论】:

  • 可能是您在此处设置的宽度和高度的 bcoz,p.setPictureSize(mPictureWidth,mPictureHeight);
  • @AndroSelva 这些值是正确的,它们都代表我要配置的分辨率。调试了一段时间发现哪里出了问题,我会尽快把答案写在这里。

标签: android camera size image


【解决方案1】:

嗯,经过一段时间的调试,我发现了问题所在。

关键是,只有在您的预览大小与之兼容的情况下,您才能设置图片大小。兼容是指它们的分辨率的纵横比(宽高比)是相同的。

示例:

宽屏预览尺寸分辨率仅支持宽屏图片尺寸分辨率。

如果您为预览尺寸设置了错误的分辨率(宽屏预览尺寸和普通屏幕图片尺寸),则图片尺寸将无法正确设置。

我创建了一个supportedPreviewSize 与supportedPictureSize 的示例

preview 800 x 600
    2048 x 1536 [ ok ]
    1600 x 1200 [ ok ]
    800  x 600  [ ok ]
    2048 x 1232 [ fail - 2048 x 1536 ]
    1600 x 960  [ fail - 1600 x 1200 ]
    1024 x 600  [ fail - 1600 x 1200 ]
    
preview 1024 x 600
    2048 x 1536 [ fail - 2048 x 1232 ]
    1600 x 1200 [ fail - 2048 x 1232 ]
    800  x 600  [ fail - 1024 x 600  ]
    2048 x 1232 [ ok ]
    1600 x 960  [ ok ]
    1024 x 600  [ ok ]

希望对以后遇到同样问题的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 2015-06-12
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多