我从网络接收样本(浮点数组)并将它们绘制为SurfaceView中的曲线。样本定期更新,因此曲线是动态的。 在我的程序中,我创建了一个将绘制曲线的Bitmap,如下所示:
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 方法只是更新新样本,也就是说,删除旧区域,以及 在该区域绘制新样本。我能怎么做?谢谢!
答案 0 :(得分: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);