나는 뷰 클래스의 하위 클래스 인 나침반을 가지고 있으며 나침반 바늘은 비트 맵입니다. 센서가 바뀔 때마다 나침반이 무효화되고 캔버스에 다시 그려지므로 나침반 바늘의 회전도 바뀝니다. 내가 겪고있는 문제는 나침반 바늘이 회전하는 것을 보았을 때 약간 뒤떨어져있는 것을 보았을 때, 기본적으로 열악한 fps입니다. 실제로 드로잉 대신에 비트 맵을 계속해서 다시 그리기 때문에 뒤떨어져있는 것 같아요. 캔버스를 그리기 위해 서페이스 뷰를 사용하면 가난한 fps가 사라지는 지 궁금합니다. 가장 좋은 방법을 해결하는 방법에 대한 정보는 크게 감사하겠습니다. 이미지는 300x300 픽셀입니다. 주요 활동에안드로이드 그래픽
센서 :
@Override
public void onSensorChanged(SensorEvent event) {
float[] v = event.values;
north = v[0];
comp.setNorth(-v[0]);
}
나침반보기 :
public void setNorth(float n) {
north_changed = true;
north = n;
invalidate();
}
그리기 비트 맵 :
private void drawCompass(Canvas canvas) {
canvas.save();
if (north_changed == true) {
canvas.rotate(north);
}
float maxwidth = (float) (canvasBitmap.getWidth() * Math.sqrt(2));
float maxheight = (float) (canvasBitmap.getHeight() * Math.sqrt(2));
float ratio = Math.min(w/maxwidth, h/maxheight);
int width = (int) (canvasBitmap.getWidth() * ratio);
int height = (int) (canvasBitmap.getHeight() * ratio);
canvas.drawBitmap(compTexture, new Rect(0, 0, compTexture.getWidth(),
compTexture.getHeight()), new Rect(-width/2, -height/2,
width/2, height/2), facePaint);
canvas.restore();
}
비트 맵을 그리는 방법을 게시 할 수 있습니까? 회전 된 이미지, 특히 300x300 픽셀 인 이미지를 그리는 경우 성능 문제가 발생하지 않아야합니다. SurfaceView를 사용하면 성능 문제를 해결하는 데 그치지 않습니다. – Samuel
코드가 추가되었습니다. – user1163392
SensorManager에 등록 할 때 사용하고있는 속도는 무엇입니까? SENSOR_DELAY_GAME 또는 SENSOR_DELAY_FASTEST를 시도하십시오. 그것은 지연이 오는 곳일 수 있습니다. – Samuel