在phone直的时候拍照
Take picture when phone is straight
我只是想问一个问题,因为我搜索了 Google,但似乎找不到任何有用的东西,并阅读了有关 this and this。
问题是,只有当 phone 笔直时才能使用 android 设备中的传感器从相机拍摄照片吗?
只是在寻找如何做的建议?
在您的 activity 中,您正在捕获图像的地方使用
int i = getResources().getConfiguration().orientation;
通过这个可以得到手机当前的方向,如果是竖屏则只抓图。
您应该能够使用方向传感器和 SensorEvents。
The orientation sensor lets you monitor the position of a device relative >to the earth's frame of reference (specifically, magnetic north).
The orientation sensor derives its data by using a device's geomagnetic >field sensor in combination with a device's accelerometer. Using these two >hardware sensors, an orientation sensor provides data for the following >three dimensions:
Azimuth (degrees of rotation around the z axis). This is the angle between magnetic north and the device's y axis. For example, if the device's y axis is aligned with magnetic north this value is 0, and if the device's y axis is pointing south this value is 180. Likewise, when the y axis is pointing east this value is 90 and when it is pointing west this value is 270.
Pitch (degrees of rotation around the x axis). This value is positive when the positive z axis rotates toward the positive y axis, and it is negative when the positive z axis rotates toward the negative y axis. The range of values is 180 degrees to -180 degrees.
Roll (degrees of rotation around the y axis). This value is positive when the positive z axis rotates toward the positive x axis, and it is negative when the positive z axis rotates toward the negative x axis. The range of values is 90 degrees to -90 degrees.
使用这些值,您应该能够判断 phone 在任何位置何时为 "straight"。 "Using the orientation sensor"header页面下有例子:http://developer.android.com/guide/topics/sensors/sensors_position.html#sensors-pos-orient
另请参阅 http://developer.android.com/reference/android/hardware/SensorEvent.html,其中显示了如何使用传感器事件
我只是想问一个问题,因为我搜索了 Google,但似乎找不到任何有用的东西,并阅读了有关 this and this。
问题是,只有当 phone 笔直时才能使用 android 设备中的传感器从相机拍摄照片吗?
只是在寻找如何做的建议?
在您的 activity 中,您正在捕获图像的地方使用
int i = getResources().getConfiguration().orientation;
通过这个可以得到手机当前的方向,如果是竖屏则只抓图。
您应该能够使用方向传感器和 SensorEvents。
The orientation sensor lets you monitor the position of a device relative >to the earth's frame of reference (specifically, magnetic north).
The orientation sensor derives its data by using a device's geomagnetic >field sensor in combination with a device's accelerometer. Using these two >hardware sensors, an orientation sensor provides data for the following >three dimensions:
Azimuth (degrees of rotation around the z axis). This is the angle between magnetic north and the device's y axis. For example, if the device's y axis is aligned with magnetic north this value is 0, and if the device's y axis is pointing south this value is 180. Likewise, when the y axis is pointing east this value is 90 and when it is pointing west this value is 270.
Pitch (degrees of rotation around the x axis). This value is positive when the positive z axis rotates toward the positive y axis, and it is negative when the positive z axis rotates toward the negative y axis. The range of values is 180 degrees to -180 degrees.
Roll (degrees of rotation around the y axis). This value is positive when the positive z axis rotates toward the positive x axis, and it is negative when the positive z axis rotates toward the negative x axis. The range of values is 90 degrees to -90 degrees.
使用这些值,您应该能够判断 phone 在任何位置何时为 "straight"。 "Using the orientation sensor"header页面下有例子:http://developer.android.com/guide/topics/sensors/sensors_position.html#sensors-pos-orient
另请参阅 http://developer.android.com/reference/android/hardware/SensorEvent.html,其中显示了如何使用传感器事件