简体   繁体   English

Android中的磁传感器和图像旋转

[英]Magnetic sensor and image rotation in Android

trying to build an magnetic compass, I have the following code. 试图建立一个磁罗经,我有以下代码。

public void onSensorChanged(SensorEvent event) {
    imageCompass = (ImageView) findViewById(R.id.imageMapDrawView);
    Bitmap myImg = BitmapFactory.decodeResource(getResources(), R.drawable.compass);
    Matrix matrix = new Matrix();
    matrix.postRotate(event.values[0] );
    Bitmap rotated = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(),
            matrix, true);
    imageCompass.setImageBitmap(rotated);
}

I have the following questions, A. I guess event.values[0] is in degree? 我有以下问题,A.我猜event.values [0]的程度? not in radian? 不是弧度? B. I want to get the image from image view and rotate it around the center of the image, where I am telling that? B.我想从图像视图中获取图像并将其围绕图像中心旋转,我在哪里告诉我? C. I want to draw another image (an indicator on top of that Image), can I do this? C.我想绘制另一个图像(该图像上方的指示器),可以这样做吗? I have already an compass image in the image view and I want to draw another image on top. 我在图像视图中已经有一个指南针图像,我想在顶部绘制另一个图像。 I can't redraw whole view. 我无法重绘整个视图。 How can I achieve it? 我该如何实现?

A. Check http://developer.android.com/reference/android/hardware/SensorEvent.html . A.检查http://developer.android.com/reference/android/hardware/SensorEvent.html

The length and contents of the values array depends on which sensor type is being monitored. 值数组的长度和内容取决于要监视的传感器类型。

Sensor.TYPE_ACCELEROMETER is in m/s²
Sensor.TYPE_MAGNETIC_FIELD is in uT (micro Tesla)
Sensor.TYPE_GYROSCOPE is in rad/s

and go on for all sensors (check the link). 并继续使用所有传感器(检查链接)。

Also, interface SensorListener is Deprecated since API level 3. You should use SensorEventListener instead. 另外,自API级别3起,不赞成使用SensorListener接口。您应该改用SensorEventListener。

B and C. You should consider using OpenGL ES for drawing your images. B和C。您应该考虑使用OpenGL ES绘制图像。 Specially OpenGL ES 2.0 gives you so much details and ways manipulate your images that would be easy to do let you do about anything you need. 特别是OpenGL ES 2.0为您提供了许多细节和操作图像的方式,这些操作很容易做到,可以让您执行所需的任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM