1

当我将其应用于从枢轴点旋转画布时,它无法正常工作。它的旋转点看起来并没有改变。我也使用矩阵应用了这个,但当时效果不佳,我发现画布旋转。我想旋转位图,并且在 UI 上还有一些其他图像。我在绘制需要旋转的位图之前旋转画布。

@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(); 
}
4

1 回答 1

0

您需要将 canvas.save() 移动到 canvas.rotate() 之前。否则,您不会将画布放回给您的状态。

于 2012-10-05T06:04:13.227 回答