2014-07-08 2 views
0

다음 코드를 사용하여 이미지를 서버에 업로드하면 성공적으로 업로드되지만 이미지 방향은 -90으로 변경됩니다.서버로 이미지 업로드 중 이미지 방향이 변경됨

이 문제를 해결하는 방법을 알지 못했습니다. Sdcard의 내 이미지가 정확한 방향이지만 왜이 이미지의 방향이 바뀌는 지 알지 못합니다.

HttpClient httpClient = new DefaultHttpClient(); 
HttpContext localContext = new BasicHttpContext(); 
HttpPost httpPost = new HttpPost(image_upload); 

Log.e("strImagePath.... before uploading", al_image_paths.get(i)); 


multipartContent.addPart("image", new FileBody(new File(al_image_paths.get(i)))); 

multipartContent.addPart("sellleadid", new StringBody("2234")); 
multipartContent.addPart("action", new StringBody("Send Used Car Images")); 
multipartContent.addPart("app_id", new StringBody("1")); 

totalSize = multipartContent.getContentLength(); 

httpPost.setEntity(multipartContent); 
HttpResponse response = httpClient.execute(httpPost, localContext); 
String serverResponse = EntityUtils.toString(response.getEntity()); 
Log.e("serverResponse image", "<> " + serverResponse); 
+2

귀하의 문제는 이미지 데이터가-회전 이미지가를 나타냅니다 EXIF ​​방향 데이터 세트가되지 않는 것입니다 그 코드 회전. 일부 시청자는 이미지를 표시 할 때 EXIF ​​방향을 고려하고 일부는 고려하지 않습니다. 처리 시간과 메모리를 절약하기 위해 대부분의 모바일 장치는 항상 특정 (일반적으로 가로 방향) 방향으로 이미지 데이터를 쓰고, 카메라를 다른 방향으로 잡고 있다면이 작은 크기의 EXIF ​​메타 데이터를 설정하여 데이터 자체를 회전하는 것보다 –

+0

@MattGibson 당신이 대답으로 게시 할 수 있다고 생각합니다 – ntv1000

+0

내 이미지 경로가 내 전화기의 올바른 이미지를 보여주기 때문에 어떤 이미지도 서버에 업로드 할 수 있습니다. – veerendra

답변

2

수동으로 회전하고 올바른 방향으로의 그것을 재 - 저장, 불행히도 이미지를로드하는 것 이외의 다른 사진 파일의 방향을 수정하는 방법은 없습니다.

당신은 이미지 회전 샘플 this 코드를 참조 할 수 있습니다

:

int rotate = 0; 
try { 
    getContentResolver().notifyChange(imageUri, null); 
    File imageFile = new File(al_image_paths.get(i)); 
    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; 
    } 
    Log.v(Common.TAG, "Exif orientation: " + orientation); 

    Bitmap rotattedBitmap= BitmapFactory.decodeFile(al_image_paths.get(i));   
    Matrix matrix = new Matrix(); 
    matrix.postRotate(rotate); 
    return Bitmap.createBitmap(rotattedBitmap, 0, 0, rotattedBitmap.getWidth(), rotattedBitmap.getHeight(), matrix, true); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

이 편집 : 귀하의 경우 , 당신은 다음을 수행해야합니다 :

  1. 확인 이미지 EXIF ​​방향
  2. 만들기 비트 맵
  3. 비트 맵 회전
  4. ,
  5. 저장 이미지와 비트 맵
  6. 서버에
  7. 이미지 업로드
+0

그래서 내 코드를 어떻게 바꿔야합니까? – veerendra

+0

@ user1761316 : 답변이 업데이트되었습니다. 또한 파일을 서버로 직접 보내고 jquery를 통해 웹 페이지의 회전 옵션을 사용할 수도 있습니다. –

+0

내가 파일 형식을 업로드해야합니다, 그래서 File.multipartContent.addPart에 비트 맵 변환 할 수 있습니다 ("이미지", 새로운 파일 바디 (새 파일 ( \t \t \t \t \t \t \t al_image_paths.get (I)))) – veerendra

0

사용

ExifInterface exif; 
int angle = 0; 
try { 
    exif = new ExifInterface(myUri.getPath()); 
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 
    if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { 
     angle = 90; 
    } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { 
     angle = 180; 
    } 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
Matrix matrix1 = new Matrix(); 

//set image rotation value to 45 degrees in matrix. 
matrix1.postRotate(angle); 

//Create bitmap with new values. 
Bitmap photo = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix1, true); 
관련 문제