我是开发Android应用程序的初学者。我的应用程序中的表面视图预览图像有问题。它显示良好但缺少图像质量。例如,我抓住了我的身份证。字母显示不好。我不明白这个词。请帮我。谢谢。这是我的代码。
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
Log.e("this is in","surfaceChanged()");
camera.stopPreview();
camera.setDisplayOrientation(0);
Thread preview_thread = new Thread(new Runnable() {
@Override
public void run() {
camera.startPreview();
}
}, "preview_thread");
preview_thread.start();
//camera.startPreview();
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
camera = Camera.open();
Log.e("this is in","surfaceCreated()");
try {
camera.setDisplayOrientation(0);
camera.setPreviewDisplay(holder);
Camera.Parameters parameters=camera.getParameters();
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
List<Size> sizes=parameters.getSupportedPictureSizes();
parameters.setPictureSize(sizes.get(0).width, sizes.get(0).height);
camera.setParameters(parameters);
camera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
// Because the CameraDevice object is not a shared resource, it's very
// important to release it when the activity is paused.
Log.e("this is in","surfaceDestroy()");
camera.stopPreview();
camera.release();
camera = null;
}
答案 0 :(得分:1)
您可以将相机的参数设置为
中第一个支持的尺寸List<Size> sizes=parameters.getSupportedPictureSizes();
parameters.setPictureSize(sizes.get(0).width, sizes.get(0).height);
这就是图片的大小。但是由于你只是从列表中取出第一个,它有点随机且高度依赖于设备。您应该过滤您真正想要的大小的列表。
同样对于预览,有两种模拟方法可以描述预览的质量
parameters.getSupportedPreviewSizes()
parameters.setPreviewSize(...)
首先找出你想要的尺寸 - 然后将其设置在参数上。