2014-02-14 3 views
2

사진은 카메라로 촬영되었지만 세로 모드는 삼성 Galaxy s3에서 사진이 회전됩니다. 어떻게하면이 문제를 해결할 수 있습니다. 다음과 같이 카메라 의도는 다음과 같습니다 결과카메라의 의도와 함께 사진 촬영 인물 사진을 회전합니다. android

에 대한

활동에
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
     intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(xdestination)); 
     startActivityForResult(intent, CAMERA_PIC_REQUEST); 

if (requestCode==CAMERA_PIC_REQUEST){ 

      // Bitmap bm = (Bitmap) data.getExtras().get("data"); 

       Uri photo_uri = Uri.fromFile(xdestination); 

       Editer.PHOTO_FROM=11; 

       Bitmap decodeSampledBitmapFromFile=null; 
       try { 
        decodeSampledBitmapFromFile = decodeUri(photo_uri); 
       } catch (FileNotFoundException e1) { 
        // TODO Auto-generated catch block 
        e1.printStackTrace(); 
       } 

       ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
       decodeSampledBitmapFromFile.compress(Bitmap.CompressFormat.JPEG,100, bytes); 

       File f = new File(Environment.getExternalStorageDirectory(), "user_image.jpg"); 

       try { 

        if(f.exists()) 
         f.delete(); 

        f.createNewFile(); 

        FileOutputStream fo = new FileOutputStream(f); 
        fo.write(bytes.toByteArray()); 
        fo.close(); 

       } catch (IOException e) { 

        e.printStackTrace(); 
        Log.d("ERROR", e.toString()); 
       } 

      } 
+0

나도 같은 문제가 있었고 캡처 한 후에 사진을 회전 시켰습니다. – InnocentKiller

+0

사진을 어떻게 회전하는지 알려주실 수 있습니까? 가능하다면 코드를 게시 하시거나 그 부분을 – user3115198

+0

아래 코드를 사용해 보시고 그렇지 않은지 알려주십시오. – InnocentKiller

답변

0

아래처럼보십시오.

File photo = new File(Environment.getExternalStorageDirectory(), "user_image.jpg"); 
     if (photo.exists()) { 
      Bitmap myBitmap = BitmapFactory.decodeFile(photo 
        .getAbsolutePath()); 
      imageView.setImageBitmap(myBitmap); 
      imageView.setRotation(90); 
     } 

1 단계 : File photo = new File(Environment.getExternalStorageDirectory() , "Face.jpg");

2 단계처럼 사진의 전체 경로를 보내기 사진 예 다음 이미지보기로 설정하고는 90도를 회전하면 존재 여부 확인.

0

사용 :

public int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath){ 
    int rotate = 0; 
    try { 
     context.getContentResolver().notifyChange(imageUri, null); 
     File imageFile = new File(imagePath); 

     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.i("RotateImage", "Exif orientation: " + orientation); 
     Log.i("RotateImage", "Rotate value: " + rotate); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return rotate; 
} 
16

당신은 선택의 여지가 있지만 읽을

private Bitmap imageOreintationValidator(Bitmap bitmap, String path) { 

    ExifInterface ei; 
    try { 
     ei = new ExifInterface(path); 
     int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, 
       ExifInterface.ORIENTATION_NORMAL); 
     switch (orientation) { 
     case ExifInterface.ORIENTATION_ROTATE_90: 
      bitmap = rotateImage(bitmap, 90); 
      break; 
     case ExifInterface.ORIENTATION_ROTATE_180: 
      bitmap = rotateImage(bitmap, 180); 
      break; 
     case ExifInterface.ORIENTATION_ROTATE_270: 
      bitmap = rotateImage(bitmap, 270); 
      break; 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    return bitmap; 
} 

private Bitmap rotateImage(Bitmap source, float angle) { 

    Bitmap bitmap = null; 
    Matrix matrix = new Matrix(); 
    matrix.postRotate(angle); 
    try { 
     bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), 
       matrix, true); 
    } catch (OutOfMemoryError err) { 
     err.printStackTrace(); 
    } 
    return bitmap; 
} 
+0

내 코드에서 가져온 것입니까? –

+0

죄송합니다. \t decodeSampledBitmapFromFile = imageOreintationValidator (decodeSampledBitmapFromFile, f.getPath()); \t \t \t \t decodeSampledBitmapFromFile.compress (Bitmap.CompressFormat.JPEG, 100, bytes); 하지만 아무 효과 이미지가 아직 조경에 있습니다 – user3115198

+0

덕분에 내 큰 문제를 해결 :) – SAndroidD

0

하여 촬영하고 올바른 방향 사진을 반환합니다 다음과 같은 방법으로 그 사진의 SDCard에 경로를 ... 통과 이미지를 회전하고 결과를 다시 SD 카드에 씁니다. BitmapFactory를 사용하는 간단한 방법은 쉽게 run into OutOfMemory exception입니다.

을 사용하거나 jpegtran을 사용할 수 있습니다.

소스 포지 (SourceForge)에는 Java 오픈 소스 클래스 LLJTran이 있습니다. Android 포트는 on GitHub입니다.

관련 문제