2014-02-10 98 views
1

我正在製作一個android應用程序,發送用戶明確採取的圖片並將其發送到Web服務器。接下來,我在Web應用程序中顯示這些圖片。Android應用程序發送圖片到Web服務器和圖片旋轉

但是,縱向拍攝從智能手機拍攝的照片出現在旋轉的服務器中,就好像它們是在橫向模式下拍攝的一樣,反之亦然。

任何想法,爲什麼發生這種情況?

+0

相關:http://stackoverflow.com/a/14066265/2345913 – CRUSADER

+0

http://stackoverflow.com/questions/14231552/uploading-image-on-server-receiving-rotated-image試試這個... –

回答

4

有一個圖像屬性,「exif標籤」。其中講述了圖像的方向。在將圖像發送到服務器之前,您可以檢查此標記的值。

您可以使用下面的方法來獲取未旋轉的圖像

public final static Bitmap getUnRotatedImage(String imahePath, Bitmap rotattedBitmap) 
    { 
     int rotate = 0; 
     try 
     { 
      File imageFile = new File(imahePath); 
      ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); 
      int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 

      switch (orientation) 
      { 
       case ExifInterface.ORIENTATION_ROTATE_270: 
        rotate = 270; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_180: 
        rotate = 180; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_90: 
        rotate = 90; 
        break; 
      } 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
      return null; 
     } 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(rotate); 
     return Bitmap.createBitmap(rotattedBitmap, 0, 0, rotattedBitmap.getWidth(), rotattedBitmap.getHeight(), matrix, 
       true); 
    } 

它有兩個參數,圖像路徑和位圖圖像。

在將圖像發送到服務器之前請嘗試此方法。

+0

thx一個你的答案 – JoaoFilipeClementeMartins

相關問題