为什么 Camera.PictureCallback() 中的图像分辨率是 PreviewSize 的大小?

发布于 2025-01-02 11:22:18 字数 988 浏览 1 评论 0原文

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

一些解释代码:

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拍照

I'm trying to use Android Camera API but when I take a picture, it's resolution is the same as my Camera object previewSize resolution.

Some code for explain:

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

How I said at the commented line, instead previewSize I want to take a picture with the pictureSize configured to my Camera

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2025-01-09 11:22:18

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

关键是,只有当您的预览尺寸与其兼容时,您才能设置图片尺寸。我所说的兼容是指它们的分辨率的宽高比(宽高比)是相同的。

示例:

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

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

我创建了一个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 ]

希望这对将来遇到同样问题的人有所帮助。

Well, after spending some time debugging I've discovered what was wrong.

The point is, you only can set the picturesize if your previewsize is compatible with it. By compatible I mean that the aspec ratio (width to height ratio) of their resolution is the same.

Example :

A wide-screen previewsize resolution only supports wide-screen picturesize resolution.

If you put a wrong resolution for a previewsize ( wide-screen previewsize with normal-screen picturesize ) then the picturesize will not be correctly set.

I've created an example of supportedPreviewSize vs 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 ]

I hope that this will help somebody who has the same problem in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文