gpt4 book ai didi

android - 禁用 Android 图像自动旋转

转载 作者:行者123 更新时间:2023-11-29 16:11:59 27 4
gpt4 key购买 nike

当我从图库中选择图像并在 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();
}
}
}
}

最佳答案

您应该自己旋转这些图像。从内容提供者读取图像方向值,特别是 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() 旋转图像。

关于android - 禁用 Android 图像自动旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12369138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com