2014-09-30 79 views
0

我在android上製作了一個自定義相機,並面臨着方向問題。 Surfaceview的活動是縱向定位,因爲這不適用於ConfigurationFchangeChanged監聽器,但我認爲它。 我想要始終以正常方向保存來自相機的圖像,但根據拍攝方向的不同,圖像會以不同的方向保存。安卓相機更改方向

代碼:

  public void onClickPicture(View view) { 
       camera.takePicture(null, null, new Camera.PictureCallback() { 
        @Override 
        public void onPictureTaken(byte[] data, Camera camera) { 
         try { 
          FileOutputStream fos = new FileOutputStream(photoFile); 
          fos.write(data); 
          fos.close(); 
          Bitmap bm = BitmapFactory.decodeByteArray(data,0,data.length); 
          ExifInterface ei; 
           ei = new ExifInterface(photoFile.getAbsolutePath()); 
           int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, 
          ExifInterface.ORIENTATION_NORMAL); 
           switch (orientation) { 
            case ExifInterface.ORIENTATION_NORMAL: 
            //ALAWAYS THIS CASE 
            break; 
            case ExifInterface.ORIENTATION_ROTATE_90: 
             bm = rotateImage(bm, 90); 
            break; 
            case ExifInterface.ORIENTATION_ROTATE_180: 
             bm = rotateImage(bm, 180); 
            break; 
            case ExifInterface.ORIENTATION_ROTATE_270: 
             bm = rotateImage(bm, 270); 
            break; 
           } 
          } catch (Exception e) { 
           e.printStackTrace(); 
        } 
       }); 
      } 
+0

如果您發佈自定義相機代碼,人們將能夠更好地爲您提供幫助。 – Mahm00d 2014-09-30 07:39:16

回答