2

Issues facing on Samsung, when I am capturing the image, the captured image get rotated. I am trying to rotate the image in the vertical direction 90 degree. On Back Facing the image get rotated with below code. But two images get stored on the device. Also issues facing while I am capturing the image on front face the image get rotated, how I can handle the image rotation in below code for both the front and back facing. Any ideas ?

                    try {
                    upload_bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                    large_bitmap = scaleDownLargeImageWithAspectRatio(upload_bitmap);
                    String fileNameLarge = "myapp_" + System.currentTimeMillis() + ".jpg";
                    large_bitmap_path = MediaStore.Images.Media.insertImage(getContentResolver(), large_bitmap, fileNameLarge, null);

                    //Start change orientation
                    String device_name = Build.MANUFACTURER;



                  if(device_name.equals("samsung"))
                   {
                        int rotate=0;
                   try {

                       String realPath = getRealPathFromUri(CameraActivity.this, Uri.parse(large_bitmap_path));
                       exif = new ExifInterface(realPath);
                        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
                        switch (orientation) {
                            case ExifInterface.ORIENTATION_ROTATE_270:
                                rotate = 270;
                                break;
                            case ExifInterface.ORIENTATION_ROTATE_180:
                                rotate = 180;
                                break;
                            case ExifInterface.ORIENTATION_ROTATE_90:
                                rotate = 90;
                                break;
                            case ExifInterface.ORIENTATION_NORMAL:
                            case ExifInterface.ORIENTATION_UNDEFINED:
                                break;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    Matrix matrix = new Matrix();
                    matrix.postRotate(90);

                  large_bitmap = Bitmap.createBitmap(large_bitmap, 0, 0, large_bitmap.getWidth(), large_bitmap.getHeight(), matrix, true);

                    horizontalList.add(large_bitmap_path);
                    horizontal_rv.smoothScrollBy(1000, 10);
                    sqLiteHelper.insertPath(large_bitmap_path, "jpg", "fileName");

                }
ADM
  • 20,406
  • 11
  • 52
  • 83
Mobile Test
  • 69
  • 1
  • 8
  • https://stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices-on-a – ADM Mar 13 '18 at 11:12
  • @ADM I followed the these tutorial but dosen't work in my case, can you please give a look on above? – Mobile Test Mar 13 '18 at 11:20

1 Answers1

1

use this library from git hub it handles all these thing related to image library link

hamza khan
  • 141
  • 1
  • 11