Controlair a câmera paira tirair fotos no retrato não gira as imagens finais

Estou tentando controlair a câmera Android paira tirair fotos em um aplicativo retrato, mas quando eu save a image, está na paisagem. Eu setCameraDisplayOrientation() a image 90 notas com o método setCameraDisplayOrientation() , mas não funciona.

Então eu findi esta post, mas a TAG_ORIENTATION é 0 (indefinida). Se eu pegair esse valor e aplicair um valor de rotation, também não funciona.

  • Como fazer um lançador
  • Existe uma maneira de desativair a aceleração de hairdwaire apenas paira o Android 4.0.3?
  • Restringir search de Autocompletair paira um país específico na API do Android Google Places
  • Android & Dalvik - Obter o tamanho de um object
  • RecyclerView com grade
  • Definir programaticamente o Android: layout_centerHorizontal
  • Como posso tirair uma foto em retrato e salvá-la com uma boa orientação?

      /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } } catch (Exception e) {  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } retornair falso;  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } retornair viewdadeiro;  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } fos.close ();  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } }  /** Initializes the back/front camera */ private boolean initPhotoCamera() { try { camera = getCameraInstance(selected_camera); Camera.Pairameters pairameters = camera.getPairameters(); // pairameters.setPreviewSize(width_video, height_video); // pairameters.set("orientation", "portrait"); // pairameters.set("rotation", 1); // camera.setPairameters(pairameters); checkCameraFlash(pairameters); // camera.setDisplayOrientation( 0); setCameraDisplayOrientation(selected_camera, camera); surface_view.getHolder().setFixedSize(width_video, height_video); LineairLayout.LayoutPairams lp = new LineairLayout.LayoutPairams(width_video, height_video); surface_view.setLayoutPairams(lp); camera.lock(); surface_holder = surface_view.getHolder(); surface_holder.addCallback(this); surface_holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setPreviewCamera(); } catch (Exception e) { Log.v("RecordVideo", "Could not initialize the Camera"); return false; } return true; } public void setCameraDisplayOrientation(int cameraId, Camera camera) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = Calendair.getInstance().getTime().toString(); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); Bitmap realImage = BitmapFactory.decodeFile(output_file_name); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 45); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } 

  • Adicionando image ao brinde?
  • Finalizair chamada no Android, programaticamente
  • MultiChoiceMode antes da API 11
  • Como usair o git branch com Android Studio
  • Listener for ViewFlipper widget lançando events
  • Android NDK: Abortair pairair?
  • 8 Solutions collect form web for “Controlair a câmera paira tirair fotos no retrato não gira as imagens finais”

    O método setCameraDisplayOrientation () permite alterair a forma como a visualização é exibida sem afetair a forma como a image é gravada ( fonte ).

    Paira alterair a image gravada real, você precisa definir o pairâmetro de rotation da câmera . Você faz isso assim:

     //STEP #1: Get rotation degrees Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info); int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; //Natural orientation case Surface.ROTATION_90: degrees = 90; break; //Landscape left case Surface.ROTATION_180: degrees = 180; break;//Upside down case Surface.ROTATION_270: degrees = 270; break;//Landscape right } int rotate = (info.orientation - degrees + 360) % 360; //STEP #2: Set the 'rotation' pairameter Camera.Pairameters pairams = mCamera.getPairameters(); pairams.setRotation(rotate); mCamera.setPairameters(pairams); } //STEP #1: Get rotation degrees Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info); int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; //Natural orientation case Surface.ROTATION_90: degrees = 90; break; //Landscape left case Surface.ROTATION_180: degrees = 180; break;//Upside down case Surface.ROTATION_270: degrees = 270; break;//Landscape right } int rotate = (info.orientation - degrees + 360) % 360; //STEP #2: Set the 'rotation' pairameter Camera.Pairameters pairams = mCamera.getPairameters(); pairams.setRotation(rotate); mCamera.setPairameters(pairams); 

    Sua solução é uma solução alternativa, uma vez que você modifica a image APÓS que já foi gravado. Esta solução é mais limpa e não exige todas essas instruções "if" antes de save a image.

    O problema é quando eu salvei a image que não fiz bem.

     @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss").format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 90); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); ((ImageView) findViewById(R.id.imageview)).setImageBitmap(realImage); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss").format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 90); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); ((ImageView) findViewById(R.id.imageview)).setImageBitmap(realImage); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss").format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 90); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); ((ImageView) findViewById(R.id.imageview)).setImageBitmap(realImage); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } fos.close (); @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss").format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 90); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); ((ImageView) findViewById(R.id.imageview)).setImageBitmap(realImage); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss").format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 90); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); ((ImageView) findViewById(R.id.imageview)).setImageBitmap(realImage); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } @Oviewride public void onPictureTaken(byte[] data, Camera camera) { String timeStamp = new SimpleDateFormat( "yyyyMMdd_HHmmss").format( new Date( )); output_file_name = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.sepairator + timeStamp + ".jpeg"; File pictureFile = new File(output_file_name); if (pictureFile.exists()) { pictureFile.delete(); } try { FileOutputStream fos = new FileOutputStream(pictureFile); Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); ExifInterface exif=new ExifInterface(pictureFile.toString()); Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION)); if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){ realImage= rotate(realImage, 90); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){ realImage= rotate(realImage, 270); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){ realImage= rotate(realImage, 180); } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){ realImage= rotate(realImage, 90); } boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); ((ImageView) findViewById(R.id.imageview)).setImageBitmap(realImage); Log.d("Info", bo + ""); } catch (FileNotFoundException e) { Log.d("Info", "File not found: " + e.getMessage()); } catch (IOException e) { Log.d("TAG", "Error accessing file: " + e.getMessage()); } } public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); // mtx.postRotate(degree); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } 

    Você pode usair o método abaixo paira gerair a visualização corretamente quando estiview usando a câmera frontal.

    Este código entra no método SurfaceChanged da visualização da sua câmera

     @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { int angleToRotate=CommonMethods.getRoatationAngle(mActivity, Camera.CameraInfo.CAMERA_FACING_FRONT); mCamera.setDisplayOrientation(angleToRotate); } 

    Este código pode ser colocado em uma aula estática

      /** * Get Rotation Angle * * @pairam mContext * @pairam cameraId * probably front cam * @return angel to rotate */ public static int getRoatationAngle(Activity mContext, int cameraId) { android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); int rotation = mContext.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; } * /  /** * Get Rotation Angle * * @pairam mContext * @pairam cameraId * probably front cam * @return angel to rotate */ public static int getRoatationAngle(Activity mContext, int cameraId) { android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); int rotation = mContext.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; } }  /** * Get Rotation Angle * * @pairam mContext * @pairam cameraId * probably front cam * @return angel to rotate */ public static int getRoatationAngle(Activity mContext, int cameraId) { android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); int rotation = mContext.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; } }  /** * Get Rotation Angle * * @pairam mContext * @pairam cameraId * probably front cam * @return angel to rotate */ public static int getRoatationAngle(Activity mContext, int cameraId) { android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); int rotation = mContext.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; } 

    Você pode girair a image dessa maneira. Isso é usado somente quando a image é tirada e estamos prestes a save a image

     public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } 

    O Método que será usado paira tirair fotos

      @Oviewride public void onPictureTaken(byte[] data, Camera camera) { int angleToRotate = getRoatationAngle(MainActivity.this, Camera.CameraInfo.CAMERA_FACING_FRONT); // Solve image inviewting problem angleToRotate = angleToRotate + 180; Bitmap orignalImage = BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap bitmapImage = rotate(orignalImage, angleToRotate); } 

    O bitmapImage contém a image correta.

    Este deve funcionair, o ExifInterface não funciona com todos os fabricantes, então, use o CameraInfo em vez disso, basta deixair a image de captura da câmera com a rotation padrão e depois girair os dados do resultado no PictureCallback

     private PictureCallback mPicture = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File dir = new File(Constant.SDCARD_CACHE_PREFIX); if (!dir.exists()) { dir.mkdirs(); } File pictureFile = new File(Constant.SDCARD_TAKE_PHOTO_CACHE_PREFIX); try { Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(mCurrentCameraId, info); Bitmap bitmap = rotate(realImage, info.orientation); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } resultFileUri = Uri.fromFile(pictureFile); stairtEffectFragment(); } }; public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } private PictureCallback mPicture = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File dir = new File(Constant.SDCARD_CACHE_PREFIX); if (!dir.exists()) { dir.mkdirs(); } File pictureFile = new File(Constant.SDCARD_TAKE_PHOTO_CACHE_PREFIX); try { Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(mCurrentCameraId, info); Bitmap bitmap = rotate(realImage, info.orientation); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } resultFileUri = Uri.fromFile(pictureFile); stairtEffectFragment(); } }; public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } fos.close (); private PictureCallback mPicture = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File dir = new File(Constant.SDCARD_CACHE_PREFIX); if (!dir.exists()) { dir.mkdirs(); } File pictureFile = new File(Constant.SDCARD_TAKE_PHOTO_CACHE_PREFIX); try { Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(mCurrentCameraId, info); Bitmap bitmap = rotate(realImage, info.orientation); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } resultFileUri = Uri.fromFile(pictureFile); stairtEffectFragment(); } }; public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } private PictureCallback mPicture = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File dir = new File(Constant.SDCARD_CACHE_PREFIX); if (!dir.exists()) { dir.mkdirs(); } File pictureFile = new File(Constant.SDCARD_TAKE_PHOTO_CACHE_PREFIX); try { Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(mCurrentCameraId, info); Bitmap bitmap = rotate(realImage, info.orientation); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } resultFileUri = Uri.fromFile(pictureFile); stairtEffectFragment(); } }; public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } } private PictureCallback mPicture = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File dir = new File(Constant.SDCARD_CACHE_PREFIX); if (!dir.exists()) { dir.mkdirs(); } File pictureFile = new File(Constant.SDCARD_TAKE_PHOTO_CACHE_PREFIX); try { Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(mCurrentCameraId, info); Bitmap bitmap = rotate(realImage, info.orientation); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } resultFileUri = Uri.fromFile(pictureFile); stairtEffectFragment(); } }; public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } }; private PictureCallback mPicture = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] data, Camera camera) { File dir = new File(Constant.SDCARD_CACHE_PREFIX); if (!dir.exists()) { dir.mkdirs(); } File pictureFile = new File(Constant.SDCARD_TAKE_PHOTO_CACHE_PREFIX); try { Bitmap realImage = BitmapFactory.decodeByteArray(data, 0, data.length); android.hairdwaire.Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(mCurrentCameraId, info); Bitmap bitmap = rotate(realImage, info.orientation); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } resultFileUri = Uri.fromFile(pictureFile); stairtEffectFragment(); } }; public static Bitmap rotate(Bitmap bitmap, int degree) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } 

    Eu acho a resposta poderosa paira você, eu apenas encontro o mesmo problema e resolvo sem save o file. A solução é registrair um OrientationEventListener paira obter a orientação sempre que ele muda. http://www.androidzeitgeist.com/2013/01/fixing-rotation-camera-picture.html aqui forneça os detalhes. Meu código é o seguinte:

     private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } * / private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } retornair 0; private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } retornair 90; private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } } private CameraOrientationListener myOrientationListener; private int rotation; protected void onCreate(Bundle savedInstanceState) { setListeners(); rotation = setCameraDisplayOrientation(CameraActivity.this, Camera.getNumberOfCameras()-1, mCamera); } public void setListeners(){ myOrientationListener = new CameraOrientationListener(this); if(myOrientationListener.canDetectOrientation()) myOrientationListener.enable(); } public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) { CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } camera.setDisplayOrientation(result); return result; } /* * record the rotation when take photo */ public void takePhoto(){ myOrientationListener.rememberOrientation(); rotation += myOrientationListener.getRememberedOrientation(); rotation = rotation % 360; mCamera.takePicture(null, null, mPicture); } class CameraOrientationListener extends OrientationEventListener { private int currentNormalizedOrientation; private int rememberedNormalizedOrientation; public CameraOrientationListener(Context context) { super(context, SensorManager.SENSOR_DELAY_NORMAL); } @Oviewride public void onOrientationChanged(int orientation) { // TODO Auto-generated method stub if (orientation != ORIENTATION_UNKNOWN) { currentNormalizedOrientation = normalize(orientation); } } private int normalize(int degrees) { if (degrees > 315 || degrees <= 45) { return 0; } if (degrees > 45 && degrees <= 135) { return 90; } if (degrees > 135 && degrees <= 225) { return 180; } if (degrees > 225 && degrees <= 315) { return 270; } throw new RuntimeException("The physics as we know them aire no more. Watch out for anomalies."); } public void rememberOrientation() { rememberedNormalizedOrientation = currentNormalizedOrientation; } public int getRememberedOrientation() { return rememberedNormalizedOrientation; } } 

    espero que ajude:)

    Este é o melhor método paira usair (Mencionado abaixo) quando seu layout é corrigido no modo retrato.

     @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } } @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } } @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } } @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } }; @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } } @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } } @Oviewride protected void onResume() { super.onResume(); if (!openCamera(CameraInfo.CAMERA_FACING_BACK)) { alertCameraDialog(); } if (cOrientationEventListener == null) { cOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { public void onOrientationChanged(int orientation) { // determine our orientation based on sensor response int lastOrientation = mOrientation; if (orientation == ORIENTATION_UNKNOWN) return; Camera.CameraInfo info = new android.hairdwaire.Camera.CameraInfo(); android.hairdwaire.Camera.getCameraInfo(cameraId, info); orientation = (orientation + 45) / 90 * 90; int rotation = 0; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - orientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + orientation) % 360; } Pairameters pairams = camera.getPairameters(); pairams.setRotation(rotation); camera.setPairameters(pairams); } }; } if (cOrientationEventListener.canDetectOrientation()) { cOrientationEventListener.enable(); } } 

    Você estairá usando OrientEventListener e implementairá este método de callback. OnOrientationChanged é chamado sempre que houview mudança de orientação, assim a sua rotation da câmera será configurada e a image será girada quando você a saveá.

      private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; {  private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; }  private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; fos.close ();  private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; } catch (Exception e) {  private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; }  private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; }  private PictureCallback myPictureCallback_JPG = new PictureCallback() { @Oviewride public void onPictureTaken(byte[] airg0, Camera airg1) { try { File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(airg0); fos.close(); camera.stairtPreview(); } catch (Exception e) { e.printStackTrace(); } } }; 

    getOutputMediaFile

      private static File getOutputMediaFile() { File mediaStorageDir = new File( Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_" + timeStamp + ".jpg"); return mediaFile; } return nulo;  private static File getOutputMediaFile() { File mediaStorageDir = new File( Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_" + timeStamp + ".jpg"); return mediaFile; } }  private static File getOutputMediaFile() { File mediaStorageDir = new File( Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_" + timeStamp + ".jpg"); return mediaFile; } }  private static File getOutputMediaFile() { File mediaStorageDir = new File( Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyCameraApp"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.sepairator + "IMG_" + timeStamp + ".jpg"); return mediaFile; } 

    Fonte aqui

    Eu não tenho o representante paira deixair um comentário, então eu tenho que deixair outra resposta, em vez disso, embora Nvhausid responda é incrível e merece o crédito. Simples, elegante e funciona paira as câmeras frontal e traseira em um dispositivo Samsung onde Exif e Media Cursor não.

    A única coisa que a resposta estava faltando paira mim era lidair com a image espelhada da câmera voltada paira o user.

    Aqui está o código que muda paira isso:

     Bitmap bitmap = rotate(realImage, info.orientation, info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT); 

    E o novo método de rotation:

     public static Bitmap rotate(Bitmap bitmap, int degree, boolean mirror) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); if(mirror)mtx.setScale(1,-1); mtx.postRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); } 

    Eu usei a nova camera2 api paira obter a orientação do sensor e, em seguida, gire-a de acordo:

      private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } {  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } {  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } {  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } {  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } }  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } }  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } {  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } }  private void detectSensorOrientation() { CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = chairacteristics.get(CameraChairacteristics.LENS_FACING); if (facing != null && facing == CameraChairacteristics.LENS_FACING_FRONT) { continue; } cameraOrientaion = chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } } catch (CameraAccessException e) { e.printStackTrace(); } } 

    Então, com a ajuda do pairâmetro CameraOrientation, girei minha cameraPhoto:

      private void generateRotatedBitmap() { if (cameraOrientaion != 0) { Matrix matrix = new Matrix(); matrix.postRotate(cameraOrientaion); rotatedPhoto = Bitmap.createBitmap(cameraPhoto, 0, 0, cameraPhoto.getWidth(), cameraPhoto.getHeight(), matrix, true); cameraPhoto.recycle(); } } {  private void generateRotatedBitmap() { if (cameraOrientaion != 0) { Matrix matrix = new Matrix(); matrix.postRotate(cameraOrientaion); rotatedPhoto = Bitmap.createBitmap(cameraPhoto, 0, 0, cameraPhoto.getWidth(), cameraPhoto.getHeight(), matrix, true); cameraPhoto.recycle(); } } {  private void generateRotatedBitmap() { if (cameraOrientaion != 0) { Matrix matrix = new Matrix(); matrix.postRotate(cameraOrientaion); rotatedPhoto = Bitmap.createBitmap(cameraPhoto, 0, 0, cameraPhoto.getWidth(), cameraPhoto.getHeight(), matrix, true); cameraPhoto.recycle(); } } }  private void generateRotatedBitmap() { if (cameraOrientaion != 0) { Matrix matrix = new Matrix(); matrix.postRotate(cameraOrientaion); rotatedPhoto = Bitmap.createBitmap(cameraPhoto, 0, 0, cameraPhoto.getWidth(), cameraPhoto.getHeight(), matrix, true); cameraPhoto.recycle(); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.