在Android中从Gallery中选择后,如何将图像设置为肖像模式?
在从“多媒体资料”中选择“图像”后,我想在“纵向”中显示图像。我使用下面的代码在Android中从Gallery中选择后,如何将图像设置为肖像模式?,android,orientation,Android,Orientation,在从“多媒体资料”中选择“图像”后,我想在“纵向”中显示图像。我使用下面的代码 findViewById(R.id.btn_open_galllery).setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { Inte
findViewById(R.id.btn_open_galllery).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent selectPictureIntent = new Intent(
Intent.ACTION_PICK);
selectPictureIntent.setType("image/*");
startActivityForResult(selectPictureIntent, 1212);
}
});
//论活动结果
Uri selectedImageUri=data.getData()
//这里我得到了图像的每次旋转,但如果图像处于横向模式,我只需要图像的纵向模式。选择图像后,必须强制更改屏幕的横向方向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
下面是检查屏幕是陆地还是港口的代码
Configuration newConfig = getResources().getConfiguration();
if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
//PORTRAIT
}else{
//Land
}
试试这个
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
if(bitmap.getHeight()< bitmap.getWidth()){
Canvas c = new Canvas(bitmap);
c.rotate(270);
}
// Your rotated image is ready you can use it now
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
位图位图=空;
试一试{
位图=MediaStore.Images.Media.getBitmap(this.getContentResolver(),selectedImageUri);
if(bitmap.getHeight()
将方向属性添加到该特定项目的清单文件中activity@Swap-IOS Android no.我只想旋转处于横向模式的图像。谢谢你的两份:
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImageUri);
if(bitmap.getHeight()< bitmap.getWidth()){
Canvas c = new Canvas(bitmap);
c.rotate(270);
}
// Your rotated image is ready you can use it now
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}