【问题标题】:Camera orientation in Portrait mode in androidandroid中人像模式下的相机方向
【发布时间】:2014-05-25 18:10:58
【问题描述】:
【问题讨论】:
标签:
android
android-camera
android-camera-intent
【解决方案1】:
我不确定您将如何进一步使用这些捕获的图像。 . .
因此,如果您要捕获并仅将其显示在 Imageview 中,最好将其旋转到 90 度并使用以下代码设置位图
public static Bitmap rotate(Bitmap b, int degrees)
{
if (degrees != 0 && b != null)
{
Matrix m = new Matrix();
m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
try {
Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
if (b != b2)
{
b.recycle();
b = b2;
}
} catch (OutOfMemoryError ex)
{
throw ex;
}
}
return b;
}
或者如果你打算将它保存到 SD 卡并使用它,在拍照后使用以前的代码旋转位图,然后将它保存在 sdcard 中。