I want to draw the 2000 points which save to data object.
I use the following code:
Bitmap bitmap = Bitmap.createBitmap(2000,100,Config.ARGB_8888);
Canvas canvasTemp=new Canvas(bitmap);
Paint paint=new Paint();
for (int i = 0; i < 2000; i++) {
canvasTemp.drawPoint(i, data.getData(i), paint);
}
Matrix matrix = new Matrix();
float scaleWidth = ((float) 640 / 2000);
float scaleHeight = ((float) 480/ 100);
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0,2000, 100, matrix, true);
canvas.drawBitmap(newbmp, 0, 0, new Paint());
This drawing speed is too slow. It needs about 5 or 6 seconds.
How to make the drawing speed more quickly?
Why not directly paint on the canvas? It saves you creating two (large) bitmaps:
Just use
concat()to scale the draw commands of the canvas.Additional note: Creating new objects (
paint,matrix, two large! bitmaps) in the draw method of aViewis not recommended. It results in lots of instance creations/deletions, which result in activating the garbage collector (GC) more often, resulting in (huge) performance issues with your application!Instead, create the
paintandmatrixobject once, in the constructor of yourView.