2017-11-13 1 views
0

나는이 회사를 싫어한다. 모든 장치에는 많은 버그가 있습니다. Ok 질문 : 나는 어리석은 문제 (내가 5 년 이상 존재한다는 것을 알고있다)를 고치려고 노력하고있다. 카메라에서 찍은 사진 - 90도 회전. 나는 두 개의 장치가 예를 들면 다음과 같습니다카메라에서 회전 한 사진 (SAMSUNG 장치)

Nexus 5p and Samsung j2 
    Nexus - work perfect. Everything fine. 
    Samsung - photo rotated 

: 몇 가지 테스트 후

Photo size - Portrate: width 1900(?????) height - 1000(????) 
rotate to landscape : width 1900 height 1000 

:

Photo size - nexus : Portrate : width 1000, height 1900. Landscape : 
width 1900 , height 1000 

는 삼성 기기에서 볼 수 있습니다 삼성 장치에서 가로 모드에서 사진을 만들 경우 - 모든 것보다 좋아. 사진이 회전되지 않음

사진을 인물로 만들 경우 - 사진이 90도 회전합니다. ???

String _path = Environment.getExternalStorageDirectory() 
            + File.separator + "camera_img.jpg"; 
          File file = new File(_path); 
          Uri outputFileUri = Uri.fromFile(file); 
          Intent intent = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
          intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
          startActivityForResult(intent, CAMERA_REQUEST); 
: (하지만 풍경 등 사진의 크기 (

사람이 바보 버그를 수정하는 방법을 알고 방법) ITS 가능한 어쩌면 어떤 방법 카메라의 방향을 감지하는 방법 임은 사진을 IntentActivity를 사용하여 말해 줄 수

도움이 필요하십니까? 삼성 전자 기기가 회전하는 것보다 체커를 추가 할 수 있습니다. 그러나 사진을 포 트릿 모드로 만들면 회전이 좋으며 가로로보기에는 문제가 없으므로 어떤 방향으로 사진이 생성되었는지 확인해야합니다. 알고 계신가요?

+0

동일한 문제가 발생했습니다. 다음 링크를 참조하십시오. https://stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices- on-a – Dhruv

+0

@DhruvPatel 사진 크기가 항상 가로 크기이기 때문에 작동하지 않습니다. – Peter

+0

풍경과 인물 사진을 인터넷 어딘가에 넣을 수 있나요? – greenapps

답변

2

을 : 잘은 정말 바보 열심히

날에 된 GetImage : 첫 번째 단계 GET

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) { 

      String _path = Environment.getExternalStorageDirectory() + File.separator + "TakenFromCamera.jpg"; 
      String p1 = Environment.getExternalStorageDirectory().toString(); 
      String fName = "/TakenFromCamera.jpg"; 
      final int rotation = getImageOrientation(_path); 
      File file = resaveBitmap(p1, fName, rotation); 
      Bitmap mBitmap = BitmapFactory.decodeFile(_path); 

주요 활동 결과는을 stesps 파일 변경 전 오리엔테이션.

(에 대한 파일

에서 올바른 비트 맵을 얻을)
3) 우리가이 단계를 건너 뛸 수 있습니다 만 미리보기가 필요한 경우, 서버에 전송해야하는 경우 (파일을 다시 저장
2)) 경로 1) getImageOrientation 충분히 1 단계와 3 단계 만 미리보고이 함수를 사용하면 비트 맵을 회전 할 수 있습니다.

private Bitmap checkRotationFromCamera(Bitmap bitmap, String pathToFile, int rotate) { 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(rotate); 
     Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 
     return rotatedBitmap; 
    } 

getImageOrientation

public static int getImageOrientation(String imagePath) { 
    int rotate = 0; 
    try { 
     ExifInterface exif = new ExifInterface(imagePath); 
     int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); 
     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 (IOException e) { 
     e.printStackTrace(); 
    } 
    return rotate; 
} 

및 resaveBitmap 이미지를 회전하려면 필요

private File resaveBitmap(String path, String filename, int rotation) { //help for fix landscape photos 
     String extStorageDirectory = path; 
     OutputStream outStream = null; 
     File file = new File(filename); 
     if (file.exists()) { 
      file.delete(); 
      file = new File(extStorageDirectory, filename); 
     } 
     try { 
      // make a new bitmap from your file 
      Bitmap bitmap = BitmapFactory.decodeFile(path + filename); 
      bitmap = checkRotationFromCamera(bitmap, path + filename, rotation); 
      bitmap = Bitmap.createScaledBitmap(bitmap, (int) ((float) bitmap.getWidth() * 0.3f), (int) ((float) bitmap.getHeight() * 0.3f), false); 
      bitmap = Utils.getCircleImage(bitmap); 
      outStream = new FileOutputStream(path + filename); 
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); 
      outStream.flush(); 
      outStream.close(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return file; 
    } 

그게 모든 :) 모든 것이 잘

0

카메라 API로 직접 사진을 찍고 있습니까? 그래서 당신과 방향을 얻을 수있는 경우 : 카메라 1의 API :

CameraInfo cameraInfo = new CameraInfo(); 
int sensorOrientation = cameraInfo.orientation; 

카메라 2의 API : 내가 해결하는 방법을 발견

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); 
CameraCharacteristics characteristics = mCameraCharacteristics; 
int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); 
+0

내 게시물을주의 깊게 읽고, 거기에 쓰십시오. im intentActivity using Camera API. – Peter

+0

죄송합니다. 불행히도 이미지 회전을 보려면 EXIF를 사용해야합니다. –

0

작동하지만 당신 만이있는 경우 이 배열을 사용할 수 있습니다 :

private byte[] rotationFromCamera(byte[] data) { 
    int rotation = Exif.getOrientation(data); 
    if(rotation == 0) return data; 
    Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, null); 
    Matrix matrix = new Matrix(); 
    matrix.postRotate(rotation); 
    Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 
    return stream.toByteArray(); 
} 

이 이미지가 크면 조금 느린이 answer

에서의 util이 EXIF.

관련 문제