0

I receive samples(float array) from network and draw them as a curve in a SurfaceView. The samples are updated periodically so the curve is dynamic. In my program, I create a Bitmap which the curve will be drawn into, like this:

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);
        ...
    }
}

I wanna support the curve can be zoom in and out. As to draw curve effectively, The drawCurve method just update the new samples, that is to say, erase a old area, and draw the new sample in that area. how can I do? Thanks!

Micheal.zu
  • 85
  • 1
  • 11
  • http://stackoverflow.com/questions/7704086/how-do-i-modify-touchimageview-with-double-tap-to-zoom-in-and-out/7816495#7816495 this will contain a library that will solve the problem – ingsaurabh May 11 '12 at 10:55

1 Answers1

0

It may help you ........... from: http://android-er.blogspot.in/2010/07/skew-bitmap-image-using-matrix.html

see drawMatrix function :

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

   Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
  • 1
    Thanks your reply! I know use matrix in drawBitmap to scale a bitmap. but it is needed to clone a new Bitmap and scale the new Bitmap, then draw back to the previous bitmap using its canvas. – Micheal.zu May 11 '12 at 11:24