2012-10-05 2 views
1

피벗 지점에서 회전 캔버스에 적용 할 때 제대로 작동하지 않습니다. 회전 지점이 변경되지 않은 것처럼 보입니다. 나는 매트릭스를 사용하여 이것을 적용했지만 그때는 캔버스로 회전하는 것을 찾는 것이 좋았다. 비트 맵을 회전하고 UI에 다른 이미지가 있습니다. 나는 회전 할 필요가있는 비트 맵을 그리기 직전에 캔버스를 회전시키고있다.setRotate (float degrees, float px, float py)를 사용하여 캔버스를 회전 하시겠습니까? 피벗 arround ... 나를 위해 올바르게 작동하지 않습니다

@Override protected void onDraw(Canvas canvas) 
{ 
    /* * draw the background */ 
    canvas.drawBitmap(mWood, 0, 0, null); 
    /* * compute the new position of our object, based on accelerometer */ 
    final ParticleSystem particleSystem = mParticleSystem; 
    final long now = mSensorTimeStamp + (System.nanoTime() - mCpuTimeStamp); 
    final float sx = mSensorX; 
    final float sy = mSensorY; 
    particleSystem.update(sx, sy, now); 
    final Bitmap bitmap = mBitmap; 
    final Bitmap bitmapOvel = mBitmapOvel; 

    Paint p = new Paint(); 
    p.setStyle(Style.FILL); 
    p.setColor(Color.GREEN); 
    canvas.drawBitmap(mWoodDial, 10, centerY - centerX + 20, null); 
    p.setColor(Color.RED); 
    p.setStyle(Style.FILL_AND_STROKE); 
    if (height <= 320) 
    { 
     p.setTextSize(14f); 
    } 
    else if (height <= 480) 
    { 
     p.setTextSize(18f); 
    } 
    else 
    { 
     p.setTextSize(26f); 
    } 
    String ss = Html.fromHtml(xx + "&#176 && " + yy + "&#176") .toString(); 
    canvas.drawBitmap(mBitmapOvelAlter, centerX + xx * 1.7f - 15f, centerY + 6f - yy, null); 
    canvas.rotate(xx, centerX, centerY); 
    p.setAntiAlias(true); 
    p.setFilterBitmap(true); 
    p.setDither(true); 
    canvas.save(); 
    canvas.drawBitmap(mWoodDial1, 10, centerY - centerX + 20, p); 
    canvas.restore(); 
    System.out.println("xx:" + xx + "::.. yy:" + yy); 
    // and make sure to redraw asap 
    invalidate(); 
} 
+0

당신은 올바른 방향으로 나아 가지 않을 것입니다. onDraw에서 무효화를 호출하지 마십시오. 끊임없이 무언가를 업데이트 할 필요가 있다면 당신은 틱하고 무효화하는 타이머를 가져야한다. 더 좋게는 서페이스 뷰를 사용하고 드로잉 루프를 직접 처리하십시오. – dcow

답변

0

canvas.srot()를 canvas.rotate() 전에 이동해야합니다. 그렇지 않으면 캔버스를 다시 당신에게 주어진 상태로 놓지 않습니다.

+1

같은 문제가있는 op.still에서 변경하지 않고 언급 한대로. – Manmohan

+1

나는 출력을 보여주고 있는데 [link part 1] (https://twitter.com/B_manmohan/status/254103298137784320/photo/1)과 기타 [link part 2] (https : // twitter .com/B_manmohan/status/254103367519981568/photo/1) – Manmohan

+0

점을 중심으로 선회하고 있습니다. 그렇다면 아마 centerX와 centerY가 맞지 않을 것입니다. – nmw