android拍照保存照片方向,android-图片保存方向错误

我正在使用此代码:

在清单中,活动方向设置为横向.

因此,就像允许用户仅在横向模式下拍照,如果通过将设备保持在纵向模式下拍照,则保存的图像如下所示:

90度旋转的图像.

在寻找解决方案之后,我发现了这一点:

解决方案在哪里:

在surfaceChanged()中检查

Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

display.getRotation();

并相应地更改相机的displayOrientation.

camera.setDisplayOrientation(90);

但是,无论我旋转设备多少次,都不会调用surfaceChanged().

我什至尝试删除Manifest.xml中的orientation =“ Landscape”,但是预览本身会横向显示(可能是因为默认的android.view.SurfaceView应该处于横向模式?).

最佳答案

尝试这个.

public void surfaceCreated(SurfaceHolder holder) {

try {

camera = Camera.open();

camParam = camera.getParameters();

Camera.Parameters params = camera.getParameters();

String currentversion = android.os.Build.VERSION.SDK;

Log.d("System out", "currentVersion " + currentversion);

int currentInt = android.os.Build.VERSION.SDK_INT;

Log.d("System out", "currentVersion " + currentInt);

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

if (currentInt != 7) {

camera.setDisplayOrientation(90);

} else {

Log.d("System out", "Portrait " + currentInt);

params.setRotation(90);

/*

* params.set("orientation", "portrait");

* params.set("rotation",90);

*/

camera.setParameters(params);

}

}

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {

// camera.setDisplayOrientation(0);

if (currentInt != 7) {

camera.setDisplayOrientation(0);

} else {

Log.d("System out", "Landscape " + currentInt);

params.set("orientation", "landscape");

params.set("rotation", 90);

camera.setParameters(params);

}

}

camera.setPreviewDisplay(holder);

camera.startPreview();

} catch (IOException e) {

Log.d("CAMERA", e.getMessage());

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值