我正在使用相机应用程序,在没有使用设备相机的情况下拍照,我这样做了,并且工作正常,但是当我们在三星设备上捕获图像时,我将图像旋转为onPictureTaken回调方法。
请让我知道我应该怎么做才能以与设备方向相同的方向获取图像。
我正在使用以下代码来设置相机旋转,但是在三星设备中却无济于事。
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
int rotation = this.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break; //Natural orientation
case Surface.ROTATION_90: degrees = 90; break; //Landscape left
case Surface.ROTATION_180: degrees = 180; break;//Upside down
case Surface.ROTATION_270: degrees = 270; break;//Landscape right
}
int rotate = (info.orientation - degrees + 360) % 360;
Camera.Parameters param = mCamera.getParameters();
param.setRotation(rotate);
mCamera.setParameters(param);
我有一个有趣的建议,我也在我的一个项目中也做了。我假设您正在使用imageView和Bitmap。现在,将您的旋转代码转换为可旋转90度的方法。然后在图像上添加一个透明按钮。每次单击图像(也单击按钮),图像将旋转90度!!例如,您可以编写这样的旋转方法;
public static Bitmap rotateBitmap(Bitmap source)
{
Matrix matrix = new Matrix();
matrix.postRotate(90);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
然后,假设您已在图像上添加了透明按钮“旋转器”,则可以将其设置为onClickListener,如下所示。它都设置了位图和imageView。
rotater.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
originalBitmap=rotateBitmap(originalBitmap);
imageView.setImageBitmap(originalBitmap);
}
});
由于图像的EXIF数据,图像旋转是一个问题。希望这个技巧适合您的需求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句