2012-09-11 4 views
1

갤러리에서 이미지를 선택하고 ImageView에서 이미지를 표시 할 때 이미지 중 일부가 90도 회전합니다.Android 이미지 자동 회전 사용 안함

어떻게 비활성화합니까?

코드 :

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main); 

    m_galleryIntent = new Intent(); 
    m_galleryIntent.setType("image/*"); 
    m_galleryIntent.setAction(Intent.ACTION_GET_CONTENT); 

    m_ProfileImageView = (ImageView) findViewById(R.id.imageView1); 

    m_ProfileImageView.setOnClickListener(new OnClickListener() 
    { 
     @Override 
     public void onClick(View v) 
     { 
      startActivityForResult(Intent.createChooser(m_galleryIntent, "Select Picture"),1);       
     } 

    }); 
} 


public Bitmap readBitmap(Uri selectedImage) 
{ 
    Bitmap bm = null; 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inSampleSize = 5; 
    AssetFileDescriptor fileDescriptor =null; 
    try 
    { 
     fileDescriptor = this.getContentResolver().openAssetFileDescriptor(selectedImage,"r"); 
    } 
    catch (FileNotFoundException e) 
    { 
     e.printStackTrace(); 
    } 
    finally 
    { 
     try 
     { 
      bm = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options); 
      fileDescriptor.close(); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 
    } 
    return bm; 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    if (resultCode == RESULT_OK) 
    { 
     if (requestCode == 1) 
     { 

      try 
      { 
       Uri imageURI = data.getData(); 
       bitmapFromFile = readBitmap(imageURI);   
       m_ProfileImageView.setImageBitmap(bitmapFromFile); 

      } 
      catch (Exception e) 
      {       
       e.printStackTrace(); 
      } 
     } 
    } 
} 
+0

기기의 방향을 바꾸 었다고 생각합니다. 풍경에 세로. 액티비티에서 android : screenOrientation = "portrait"를 사용하여 가로 모드로 작업하지 못하도록하십시오. –

+0

나는 방향을 바꾸지 않습니다. 나는 그것을 시도했다, 그것은 문제가 아니다. 하지만 고마워요. – Rami

답변

4

이 이미지를 직접 회전해야한다. 콘텐츠 공급자, 특히 Images.Media.ORIENTATION 필드에서 이미지 방향 값을 읽고 이에 따라 회전합니다.

이 이미지는 회전 저장됩니다. 회전 각도는 미디어 데이터베이스에 저장됩니다.

public int getOrientation(Uri selectedImage) { 
    int orientation = 0; 
    final String[] projection = new String[]{MediaStore.Images.Media.ORIENTATION};  
    final Cursor cursor = context.getContentResolver().query(selectedImage, projection, null, null, null); 
    if(cursor != null) { 
     final int orientationColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION); 
     if(cursor.moveToFirst()) { 
      orientation = cursor.isNull(orientationColumnIndex) ? 0 : cursor.getInt(orientationColumnIndex); 
     } 
     cursor.close(); 
    } 
    return orientation; 
} 

예를 들어 ImageView.setImageMatrix()을 사용하여 이미지를 회전 할 수 있습니다.