本文介绍了三星的Galaxy S4图像捕捉问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序。我创建了一个自定义相机类捕捉图像。这是工作的罚款在索姆许多设备,但是当我试图与三星Galaxy S4返回图像灰度林家,如图所示。我的code是:

 ![`*公共无效surfaceCreated(SurfaceHolder持有者){
    frontCam = SharedUser prefs.getShared prefData(AutoCapture.this,
            Constants.IS_FRONT_CAMERA);

    如果(frontCam.equals(Constants.VALUE_ON)){

        为(中间体camIdx = 0; camIdx&其中; Camera.getNumberOfCameras(); camIdx ++){
            Camera.getCameraInfo(camIdx,cameraInfo);
            如果(cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT){
                尝试 {
                    mCamera = Camera.open(camIdx);
                }赶上(RuntimeException的E){
                    Log.e(TAG,
                            摄像头无法打​​开:
                                    + e.getLocalizedMessage());
                }
            }
        }

    } 其他 {
        mCamera = Camera.open();
    }
    mCamera.setDisplayOrientation(90);
    Camera.Parameters p值= mCamera.getParameters();
    如果(getPackageManager()。hasSystemFeature(
            PackageManager.FEATURE_CAMERA_FLASH)){
        如果(flashOn.equals(Constants.VALUE_ON)){
            {
                p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            }
        }
    } 其他 {
        p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    }
    p.setPictureFormat(ImageFormat.JPEG);

    名单< Camera.Size> previewSizes = p.getSupported previewSizes();
    Camera.Size previewsize = previewSizes.get(0);
    对于(Camera.Size大小:previewSizes){
        Log.d(宽度---+ size.width,高度---+ size.height);
    }

    P.SET previewSize(previewsize.width,previewsize.height);

    mCamera.setParameters(对);

}

公共无效surfaceChanged(SurfaceHolder持有人,INT格式,INT W,INT高){
    Log.e(TAG,surfaceChanged);

    如果(M previewRunning){
        mCamera.stop preVIEW();
    }

    尝试 {
        mCamera.set previewDisplay(保持器);

    }赶上(IOException异常E){

        的System.out.println(表面chagned捕获的异常);
        e.printStackTrace();
    }
    mCamera.start preVIEW();
    米previewRunning = TRUE;

}

公共无效surfaceDestroyed(SurfaceHolder持有者){
    Log.e(TAG,surfaceDestroyed);

    如果(M previewRunning == FALSE){
        如果(mCamera!= NULL){
            米previewRunning = FALSE;
            mCamera.stop preVIEW();
            mCamera.release();
        }
        如果(mCamera!= NULL){
            米previewRunning = FALSE;
            mCamera.release();
        }
    } / *
     *否则,如果(mCamera!= NULL){M-previewRunning = FALSE;
     * mCamera.stop preVIEW(); mCamera.release(); }
     * /

} *`] [2]
 

解决方案

我觉得你有我和这个其他人也做了同样的问题。

Samsung银河S4,图像被同时从相机采取损坏

I am developing an Android Application. I created a custom camera class to capture images. It is working fine in som many devices but when i Tried it with Samsung Galaxy S4 it returns image with gray lins as shown. My Code is :

![`*public void surfaceCreated(SurfaceHolder holder) {
    frontCam = SharedUserPrefs.getSharedPrefData(AutoCapture.this,
            Constants.IS_FRONT_CAMERA);

    if (frontCam.equals(Constants.VALUE_ON)) {

        for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); camIdx++) {
            Camera.getCameraInfo(camIdx, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                try {
                    mCamera = Camera.open(camIdx);
                } catch (RuntimeException e) {
                    Log.e(TAG,
                            "Camera failed to open: "
                                    + e.getLocalizedMessage());
                }
            }
        }

    } else {
        mCamera = Camera.open();
    }
    mCamera.setDisplayOrientation(90);
    Camera.Parameters p = mCamera.getParameters();
    if (getPackageManager().hasSystemFeature(
            PackageManager.FEATURE_CAMERA_FLASH)) {
        if (flashOn.equals(Constants.VALUE_ON)) {
            {
                p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
            }
        }
    } else {
        p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
    }
    p.setPictureFormat(ImageFormat.JPEG);

    List<Camera.Size> previewSizes = p.getSupportedPreviewSizes();
    Camera.Size previewsize = previewSizes.get(0);
    for (Camera.Size size : previewSizes) {
        Log.d("Width---" + size.width, "Height---" + size.height);
    }

    p.setPreviewSize(previewsize.width, previewsize.height);

    mCamera.setParameters(p);

}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    Log.e(TAG, "surfaceChanged");

    if (mPreviewRunning) {
        mCamera.stopPreview();
    }

    try {
        mCamera.setPreviewDisplay(holder);

    } catch (IOException e) {

        System.out.println("Caught exception in surface chagned");
        e.printStackTrace();
    }
    mCamera.startPreview();
    mPreviewRunning = true;

}

public void surfaceDestroyed(SurfaceHolder holder) {
    Log.e(TAG, "surfaceDestroyed");

    if (mPreviewRunning == false) {
        if (mCamera != null) {
            mPreviewRunning = false;
            mCamera.stopPreview();
            mCamera.release();
        }
        if (mCamera != null) {
            mPreviewRunning = false;
            mCamera.release();
        }
    }/*
     * else if (mCamera != null) { mPreviewRunning = false;
     * mCamera.stopPreview(); mCamera.release(); }
     */

}*`][2]
解决方案

I think you have the same issue me and this other guy did.

Samsung Galaxy S4 , Image gets corrupted while taking from camera

这篇关于三星的Galaxy S4图像捕捉问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 15:32