Samsung galaxy S4 image capture Issue

久未见 提交于 2019-12-30 07:15:10

问题


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]

回答1:


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

Samsung Galaxy S4 , Image gets corrupted while taking from camera



来源:https://stackoverflow.com/questions/16732123/samsung-galaxy-s4-image-capture-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!