0

I would like to launch the native Android camera and save captured image at a specified location, but when I do that and i try to reach the photo later ,saved imaged is 90 degree rotated by itself. i am using a LG cellphone to run the program. I have been already tried a solution that i found here, but they did not work. I put my code for you here... please correct me or give me a new solution. Thank you a lot

 private void cameraIntent() {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       intent.putExtra("photo", true);
      intent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
     intent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1);
     intent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true);
      startActivityForResult(intent, REQUEST_CAMERA);
    }

     public void onActivityResult(int requestCode, int resultCode, Intent data) {

            super.onActivityResult(requestCode, resultCode, data);
     if (resultCode == Activity.RESULT_OK) {
              if (requestCode == REQUEST_CAMERA)
                  onCaptureImageResult(data);
            }
    }



    private void onCaptureImageResult(Intent data) {


      ByteArrayOutputStream bytes = null;
             Bitmap thumbnail = (Bitmap) data.getExtras().get("data");

                    bytes = new ByteArrayOutputStream();
                    thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);

                File destination = new File(getExternalStorageDirectory(),
                        File.separator + "profile.jpg");

                FileOutputStream fo;
                try {
                    destination.createNewFile();
                    fo = new FileOutputStream(destination);
                    fo.write(bytes.toByteArray());
                    fo.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }


            String address = getExternalStorageDirectory().getAbsolutePath();
     ExifInterface   exif = null;
            try {
                if(destination.exists()) {
                      exif = new ExifInterface(address+File.separator+"profile.jpg");

                    Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }



            if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){
                thumbnail= rotate(thumbnail, 90);
            }else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){
                thumbnail= rotate(thumbnail, 270);
            }else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){
                thumbnail= rotate(thumbnail, 270);

            }



            resized = Bitmap.createScaledBitmap(thumbnail, navUserImage.getWidth(), navUserImage.getHeight(), true);
          navUserImage.setImageBitmap(resized);
    }
sepide
  • 1

1 Answers1

0

It does not rotate in all devices. You can try this solution. I have worked on something similar, and it suited me well.

sharp
  • 1,191
  • 14
  • 39