2014-02-10 101 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

相关问题