为什么 Camera.PictureCallback() 中的图像分辨率是 PreviewSize 的大小?
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,经过一段时间的调试,我发现了问题所在。
关键是,只有当您的预览尺寸与其兼容时,您才能设置图片尺寸。我所说的兼容是指它们的分辨率的宽高比(宽高比)是相同的。
示例:
宽屏预览尺寸分辨率仅支持宽屏图片尺寸分辨率。
如果您为预览尺寸设置了错误的分辨率(宽屏预览尺寸和普通屏幕图片尺寸),则图片尺寸将无法正确设置。
我创建了一个supportedPreviewSize 与supportedPictureSize 的示例,
希望这对将来遇到同样问题的人有所帮助。
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
I hope that this will help somebody who has the same problem in the future.