我无法更改 Android 相机分辨率
这是我在 onPreviewFrame 方法中的代码。
SurfaceHolder 上显示的框架很好。
我一开始已经用这段代码设置了分辨率
mCameraParameter = mCamera.getParameters();
mCameraParameter.setPreviewSize(100,150);
mCameraParameter.setPreviewFrameRate(20);
mCameraParameter.setPreviewFormat(PixelFormat.JPEG);
mCamera.setParameters(mCameraParameter);
,但是图像得到的图片是 640 * 480
我想知道为什么我不能更改预览分辨率。
public void onPreviewFrame(byte[] data, Camera camera) {
Log.e("PreviewCallBack", "Preview");
Camera.Parameters parameters = camera.getParameters();
Log.e("Picture Size", "width : " + parameters.getPreviewSize().width);
Log.e("Picture Size", "height : " + parameters.getPreviewSize().height);
Log.e("Array Size", "data.length : " + data.length);
YuvImage image = new YuvImage(data, parameters.getPreviewFormat(),
parameters.getPreviewSize().width,parameters.getPreviewSize().height, null);
File file = new File(Environment.getExternalStorageDirectory()
.getPath() + "/"+/*System.currentTimeMillis()*/"out.jpg");
FileOutputStream filecon = null;
try {
filecon = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
image.compressToJpeg(
new Rect(0, 0, image.getWidth(), image.getHeight()), 90,
filecon);
}
};
This is my code in onPreviewFrame Method.
The frame that shows on the surfaceHolder is fine.
I Already set the resolution with this code at first
mCameraParameter = mCamera.getParameters();
mCameraParameter.setPreviewSize(100,150);
mCameraParameter.setPreviewFrameRate(20);
mCameraParameter.setPreviewFormat(PixelFormat.JPEG);
mCamera.setParameters(mCameraParameter);
but the picture that image get is 640 * 480
I wonder why i can't change the preview resolution.
public void onPreviewFrame(byte[] data, Camera camera) {
Log.e("PreviewCallBack", "Preview");
Camera.Parameters parameters = camera.getParameters();
Log.e("Picture Size", "width : " + parameters.getPreviewSize().width);
Log.e("Picture Size", "height : " + parameters.getPreviewSize().height);
Log.e("Array Size", "data.length : " + data.length);
YuvImage image = new YuvImage(data, parameters.getPreviewFormat(),
parameters.getPreviewSize().width,parameters.getPreviewSize().height, null);
File file = new File(Environment.getExternalStorageDirectory()
.getPath() + "/"+/*System.currentTimeMillis()*/"out.jpg");
FileOutputStream filecon = null;
try {
filecon = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
image.compressToJpeg(
new Rect(0, 0, image.getWidth(), image.getHeight()), 90,
filecon);
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您正在尝试设置不受支持的预览尺寸。在调用setPreviewSize()之前,最好先调用“getSupportedPreviewSizes()”并检查您的设备是否支持您要设置的预览尺寸。
Maybe you are trying to set an unsupported preview size. Better call "getSupportedPreviewSizes()" and check if the preview size you want to set is supported by your device before calling setPreviewSize().
我认为你应该打电话
setPictureSize()
设置图片本身的大小(而不是预览)。I think you should call
setPictureSize()
to set the size of the picture itself (not the preview).