Android SurfaceView预览模糊 [英] Android SurfaceView Preview Blurry

查看:993
本文介绍了Android SurfaceView预览模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简短的问题.我正在使用Android的SurfaceView拍照并保存.但是,预览大小和图像质量本身都很糟糕.因为它非常模糊.图像质量根本没有清晰度.

I have a quick question. I'm using Android's SurfaceView to take a picture and save it. However, the preview size and the picture quality itself is both terrible; as in, it is very blurry. There's no sharpness to the picture quality at all.

在这里我初始化我的SurfaceView:

Here's where I initialize my surfaceView:

                    camera.setDisplayOrientation(90);
                    Parameters parameters = camera.getParameters();
                    parameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
                    parameters.setExposureCompensation(0);
                    parameters.setPictureFormat(ImageFormat.JPEG);
                    parameters.setJpegQuality(100);

                    Camera.Size picSize =   getOptimalPreviewSize(parameters.getSupportedPreviewSizes(),
                            getResources().getDisplayMetrics().widthPixels, 
                            getResources().getDisplayMetrics().heightPixels);

                    parameters.setPictureSize(picSize.width, picSize.height);
                    parameters.setPreviewSize(picSize.width, picSize.height);

                    camera.setParameters(parameters);
                    camera.setPreviewDisplay(holder);
                    camera.startPreview();

getOptimalPreviewSize()返回可以从parameters.getSupportedPreviewSizes()获得的最佳大小.它返回的尺寸为1280x720,这是我的手机将支持的最佳尺寸.但是,surfaceView仍然非常模糊.我在做任何明显的错误,还是有一种方法可以优化surfaceView?谢谢.

The getOptimalPreviewSize() returns the best size available from parameters.getSupportedPreviewSizes(). The size that it returns is 1280x720, the best size that my phone will support. However, the surfaceView is still very blurry. Is there anything obviously wrong that I'm doing, or is there a way to optimize the surfaceView? Thanks.

推荐答案

图像和预览可能显示模糊的原因有两个

There are two reason why your image and preview may appear blurry

1)您设置图片尺寸和预览尺寸的方式是错误的.您必须查询受支持的尺寸,然后确定哪种尺寸最适合您,然后从已获得的列表中设置尺寸.您不能提供仲裁值.检查此示例应用以获取实施细节- https://github.com/josnidhin/Android-Camera-例子

1) the way you are settings the picture size and preview size is wrong. You have to query the supported sizes and decide which is the best size for you and set size from the list that your have got. You cannot give arbit values. Check this sample app for implementation details - https://github.com/josnidhin/Android-Camera-Example

2)您必须将相机置于自动对焦模式,以使其自动对焦. (最好是通过适当的ui实现触摸以进行聚焦).相机启动后,只需进行以下设置

2) you have to put your camera in auto foucs mode so that it will focus automatically. (better is to implement a touch to focus with a proper ui). Once your camera starts just set the below

private void setCamFocusMode(){

    if(null == mCamera) {
        return;
     }

    /* Set Auto focus */ 
    Parameters parameters = mCamera.getParameters();
    List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);   
    } else if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    }   

    mCamera.setParameters(parameters);
}

确保您在清单中拥有适当的权限

make sure your have the proper permission in your manifest

希望这会有所帮助

关于, 收缩

这篇关于Android SurfaceView预览模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆