-1

enter image description here

I donot have isssue on portrait,landscape it got shrinked

Raja Sankar
  • 39
  • 10
  • You must have defined the picture aspect ratio or the pixel combo somewhere. Can't help without looking at the code that you are using to take the picture. – Q2x13 Feb 27 '17 at 08:51
  • Camera.Size previewSize = parameters.getSupportedPreviewSizes().get(0); for (Camera.Size size : parameters.getSupportedPreviewSizes()) { if (size.width >= cameraLayout.getLayoutParams().width && size.height >= cameraLayout.getLayoutParams().height) { previewSize = size; break; } } parameters.setPreviewSize(previewSize.width, previewSize.height); – Raja Sankar Feb 27 '17 at 08:53
  • this is the code i used for preview size.actually i rotated picture from landscape to portrait.i got issue while rotating picture – Raja Sankar Feb 27 '17 at 08:54
  • @RajSankar Read this. https://stackoverflow.com/questions/21668394/camera-in-android-how-to-get-best-size-preview-size-picture-size-view-size – Q2x13 Feb 27 '17 at 08:57
  • What exacly is your question? – Dieter Meemken Feb 27 '17 at 09:02
  • i try to show picture in portrait(90) even if user took picture in landscape or landscape inverted or portrait inverted.taken picture got shrinked.if i rotate an angle before saving..preview is not at all problem – Raja Sankar Feb 27 '17 at 10:07
  • How do you save the captured picture? Did you choose your `setPictureSize()` to fit the preview aspect ratio? – Alex Cohn Feb 27 '17 at 13:46
  • @AlexCohn Thank you for your reply.picture taken from portrait is fit as per this code( Camera.Size previewSize = parameters.getSupportedPreviewSizes().get(0); for (Camera.Size size : parameters.getSupportedPreviewSizes()) { if (size.width >= cameraLayout.getLayoutParams().width && size.height >= cameraLayout.getLayoutParams().height) { previewSize = size; break; } } parameters.setPreviewSize(previewSize.width, previewSize.height); ) – Raja Sankar Feb 28 '17 at 04:41
  • now i am facing rotated picture aspect ratio.i try to rotate from landscape to portrait finally picture is shrinked.i attached above with this queston – Raja Sankar Feb 28 '17 at 04:43
  • You pasted the way you choose the *preview size*, but capture uses _**picture** size_. At any rate, do you expect people to debug your program without seeing all relevant code? – Alex Cohn Feb 28 '17 at 09:20

2 Answers2

0

This is the code used for surface view

@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { if (holder.getSurface() == null) { return; }strong text try { mCamera.stopPreview(); } catch (Exception e) { } mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes(); for (Camera.Size str : mSupportedPreviewSizes) Log.e(TAG, str.width + "/" + str.height); try { Camera.Parameters parameters = mCamera.getParameters();

        Camera.Size previewSize = parameters.getSupportedPreviewSizes().get(0);
        for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
            if (size.width >= cameraLayout.getLayoutParams().width && size.height >= cameraLayout.getLayoutParams().height) {
                previewSize = size;
                break;
            }
        }
        parameters.setPreviewSize(previewSize.width, previewSize.height);
        List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
        int w = 0, h = 0;
        for (Size size : sizes) {
            if (size.width > w || size.height > h) {
                w = size.width;
                h = size.height;
            }
        }
        parameters.setPictureSize(w, h);
        List<String> focusModes = parameters.getSupportedFocusModes();
        if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        parameters.setJpegQuality(100);
        mCamera.setParameters(parameters);
    } catch (Exception e) {
    }
    setDisplayOrientation();
    setErrorCallback();
    mCamera.startPreview();
}
Raja Sankar
  • 39
  • 10
0
Actually,i facing problem in rotating a taken picture.if i took picture in ortrait or portrait inverted.=,picture taken was awesome.but if i took picture in landscape /inverted landscape,my captured image got shrinked,i posted below code about orientation shrinking issue.its not about preview shrinking.
    Camera.PictureCallback mPicture = new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {
            Const.image_type = "image";
            scanFile(Const.image_file.getAbsolutePath());
            // Intent intent = new Intent(getContext(), Publish_View.class);
            Intent intent = new Intent(getContext(), PhotoPreview.class);
            intent.putExtra("filepath", Const.image_file.getAbsolutePath());
            intent.putExtra("videofilepath", "");
            //  intent.putExtra("picture", "");
            intent.putExtra("gallery", "");
            startActivity(intent);
            getActivity().finish();
            isFlashOn = false;
            //turnOffFlash();

            if (pictureFile == null) {
                safeToTakePicture = true;
                return;
            }

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 6;
            options.inDither = false;
            options.inPurgeable = true;
            options.inInputShareable = true;
            options.inTempStorage = new byte[32 * 1024];
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            Bitmap bMap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
            int orientation;
            if (bMap.getHeight() < bMap.getWidth()) {
                orientation = setOrientation;
            } else {
                orientation = setOrientation;
            }

            Bitmap bMapRotate;
            if (orientation != 0) {
                Matrix matrix = new Matrix();
                matrix.postRotate(orientation);
                bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, true);
            } else {
                bMapRotate = Bitmap.createScaledBitmap(bMap, bMap.getWidth(), bMap.getWidth(), true);
            }
            try {
                FileOutputStream out = new FileOutputStream(pictureFile);
                bMapRotate.compress(Bitmap.CompressFormat.JPEG, 100, out);
                if (bMapRotate != null) {
                    bMapRotate.recycle();
                    bMapRotate = null;
                }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            mCamera.startPreview();
            safeToTakePicture = true;
            isFlashOn = false;
            isFrontCam = false;
            image_staus = false;
        }
    };


    private class SimpleOrientationEventListener extends OrientationEventListener {

        public SimpleOrientationEventListener(Context context) {
            super(context, SensorManager.SENSOR_DELAY_NORMAL);
        }


        @Override
        public void onOrientationChanged(int orientation) {
            // We keep the last known orientation. So if the user first orient
            // the camera then point the camera to floor or sky, we still have
            // the correct orientation.
//            if (orientation == ORIENTATION_UNKNOWN) return;
//            mOrientation = Util.roundOrientation(orientation, mOrientation);
//            // When the screen is unlocked, display rotation may change. Always
//            // calculate the up-to-date orientationCompensation.
//            int orientationCompensation = mOrientation
//                    + Util.getDisplayRotation(getActivity());
//            if (mOrientationCompensation != orientationCompensation) {
//                mOrientationCompensation = orientationCompensation;
//                mFaceView.setOrientation(mOrientationCompensation);
//                Log.d("fkjkf","gkjksjgj");
//
//            }


            // determine our orientation based on sensor response
            int lastOrientation = mOrientation;

            if (orientation >= 315 || orientation < 45) {
                if (mOrientation != ORIENTATION_PORTRAIT_NORMAL) {
                    mOrientation = ORIENTATION_PORTRAIT_NORMAL;
                }
            } else if (orientation < 315 && orientation >= 225) {
                if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) {
                    mOrientation = ORIENTATION_LANDSCAPE_NORMAL;
                }
            } else if (orientation < 225 && orientation >= 135) {
                if (mOrientation != ORIENTATION_PORTRAIT_INVERTED) {
                    mOrientation = ORIENTATION_PORTRAIT_INVERTED;
                }
            } else { // orientation <135 && orientation > 45
                if (mOrientation != ORIENTATION_LANDSCAPE_INVERTED) {
                    mOrientation = ORIENTATION_LANDSCAPE_INVERTED;
                }
            }

            if (lastOrientation != mOrientation) {
                 changeRotation(mOrientation);
                Log.d("checktry", String.valueOf(mOrientation));
                mFaceView.setOrientation(mOrientation);
            }
        }
    }


private void changeRotation(int orientation) {
        switch (orientation) {
            case ORIENTATION_PORTRAIT_NORMAL:

                if (isFrontCam) {
                    setOrientation = 270;
                    Log.v("CameraActivity", "Orientation = 270");
                } else {
                    setOrientation = 90;
                    Log.v("CameraActivity", "Orientation = 90");
                }
                break;
            case ORIENTATION_LANDSCAPE_NORMAL:
                if (isFrontCam) {
                    setOrientation = 0;
                    Log.v("CameraActivity", "Orientation = 0");
                } else {
                    Log.v("CameraActivity", "Orientation = 0");
                    setOrientation = 0;
                }

                break;
            case ORIENTATION_PORTRAIT_INVERTED:
                if (isFrontCam) {
                    setOrientation = 90;
                    Log.v("CameraActivity", "Orientation = 90");
                } else {
                    Log.v("CameraActivity", "Orientation = 270");
                    setOrientation = 270;
                }

                break;
            case ORIENTATION_LANDSCAPE_INVERTED:
                if (isFrontCam) {
                    setOrientation = 180;
                    Log.v("CameraActivity", "Orientation = 180");
                } else {
                    Log.v("CameraActivity", "Orientation = 180");
                    setOrientation = 180;
                }

                break;
        }
    }
Raja Sankar
  • 39
  • 10