当我从图库中选择图像并在 ImageView 中显示图像时,一些图像会自动旋转 90 度。
如何禁用此功能?
代码:
@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();
}
}
}
}