[英]Magnetic sensor and image rotation in Android
試圖建立一個磁羅經,我有以下代碼。
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);
}
我有以下問題,A.我猜event.values [0]的程度? 不是弧度? B.我想從圖像視圖中獲取圖像並將其圍繞圖像中心旋轉,我在哪里告訴我? C.我想繪制另一個圖像(該圖像上方的指示器),可以這樣做嗎? 我在圖像視圖中已經有一個指南針圖像,我想在頂部繪制另一個圖像。 我無法重繪整個視圖。 我該如何實現?
A.檢查http://developer.android.com/reference/android/hardware/SensorEvent.html 。
值數組的長度和內容取決於要監視的傳感器類型。
Sensor.TYPE_ACCELEROMETER is in m/s²
Sensor.TYPE_MAGNETIC_FIELD is in uT (micro Tesla)
Sensor.TYPE_GYROSCOPE is in rad/s
並繼續使用所有傳感器(檢查鏈接)。
另外,自API級別3起,不贊成使用SensorListener接口。您應該改用SensorEventListener。
B和C。您應該考慮使用OpenGL ES繪制圖像。 特別是OpenGL ES 2.0為您提供了許多細節和操作圖像的方式,這些操作很容易做到,可以讓您執行所需的任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.