0

我从网络接收样本(浮点数组)并将它们绘制为 SurfaceView 中的曲线。样本会定期更新,因此曲线是动态的。在我的程序中,我创建了一个将绘制曲线的位图,如下所示:

Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_4444);
Canvas canvas = new Canvas(bmp);
drawCurve(canvas);

void drawCurve(Canvas canvas, float[] buffer) {
      ...
      canvas.drawLine(x1, buffer[i], x2, buffer[i+1], paint);
      ...
}

...

private class RenderThread extends Thread {
    public void run() {
        c = mHolder.lockCanvas(null);
        c.drawBitmap(bmp, 0, 0, null);
        mHolder.unlockCanvasAndPost(c);
        ...
    }
}

我想支持曲线可以放大和缩小。为了有效地绘制曲线,drawCurve方法只是更新新样本,即擦除旧区域,并在该区域绘制新样本。我能怎么做?谢谢!

4

1 回答 1

0

它可以帮助你............来自:http ://android-er.blogspot.in/2010/07/skew-bitmap-image-using-matrix.html

参见 drawMatrix 函数:

   matrix.postScale(curScale, curScale);
   matrix.postRotate(curRotate);
   matrix.postSkew(curSkewX, curSkewY);

   Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
于 2012-05-11T11:13:14.330 回答