0

Actually There two problem I am facing Right now in my application.

1)Getting RuntimeException while Using Front Camera.

2)orientation of capture image using back camera is device dependent, means that in some device I got perfectly fine orientation but in some device not.

According to site rules I shouldn't asking two question at in single question but root of problem is same in both question which is setParameters so I am asking in single question.

Code:

Responsible for Capture Image.

    public void TakeImage(){
//        try {
            Camera.Parameters param;
            param = mCamera.getParameters();
            param.setRotation(90);
            Camera.Size bestSize = null;
            List<Camera.Size> sizeList = mCamera.getParameters().getSupportedPreviewSizes();
            bestSize = sizeList.get(0);
            for (int i = 1; i < sizeList.size(); i++) {
                if ((sizeList.get(i).width * sizeList.get(i).height) > (bestSize.width * bestSize.height)) {
                    bestSize = sizeList.get(i);
                }
            }

            List<Integer> supportedPreviewFormats = param.getSupportedPreviewFormats();
            Iterator<Integer> supportedPreviewFormatsIterator = supportedPreviewFormats.iterator();
            while (supportedPreviewFormatsIterator.hasNext()) {
                Integer previewFormat = supportedPreviewFormatsIterator.next();
                if (previewFormat == ImageFormat.YV12) {
                    param.setPreviewFormat(previewFormat);
                }
            }

            param.setPreviewSize(bestSize.width, bestSize.height);

            param.setPictureSize(bestSize.width, bestSize.height);

            mCamera.setParameters(param);
            mCamera.takePicture(null, null, mPicture);
//        }
//        catch (Exception e){
//            Toast.makeText(getApplicationContext(),"camera capture exception",Toast.LENGTH_SHORT).show();
//        }

    }

LogCate while using front camera Exception:

2019-04-19 10:49:14.054 20679-20679/com.example.clapdetection E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.clapdetection, PID: 20679
    java.lang.RuntimeException: setParameters failed
        at android.hardware.Camera.native_setParameters(Native Method)
        at android.hardware.Camera.setParameters(Camera.java:1980)
        at com.example.clapdetection.Activity.CameraActivity.TakeImage(CameraActivity.java:465)
        at com.example.clapdetection.Activity.CameraActivity$1$1.onClick(CameraActivity.java:110)
        at android.view.View.performClick(View.java:5637)
        at android.view.View$PerformClick.run(View.java:22433)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6126)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
earthling
  • 147
  • 16
  • 1
    https://stackoverflow.com/a/33580067/4168607 – ADM Apr 22 '19 at 05:31
  • @ADM I solve the issue of front camera by using your link but orientation is still differ in different devices so can you provide your help for it – earthling Apr 22 '19 at 06:09
  • 1
    Have you set the Orientation cause i do not see it in this code? See https://stackoverflow.com/questions/4645960/how-to-set-android-camera-orientation-properly.. – ADM Apr 22 '19 at 06:20
  • re: correct preview orientation, the essential part (see https://stackoverflow.com/a/10218309/192373) is to check `android.hardware.Camera.CameraInfo.orientation` – Alex Cohn Apr 22 '19 at 20:25

0 Answers0