In my application, I deployed my own SVG converter, which translates a raw SVG XML file into a sequence of graphic vector objects (Paint, Path, etc.), which are then applied to Canvas. SVG data is first converted to bytecode format along with lists of paths, etc., which means that the initial XML parsing is performed once, and then each redrawing of SVG graphics can happen quite quickly. The fact that SVG conversion is performed at runtime allows me to perform some programmatic manipulations on various graphic elements. For example, I can draw a graphical temperature sensor in Inkscape, and at runtime the code manipulates the calibration scale and moves the pointer around. That's why I need to "draw as static background graphics,and moving graphics using vector operations, as opposed to compiling static bitmaps. "Anyway, this is a bit of background information about what I'm doing; I will get to the real issue.
Let's say a typical calibration widget consists of two superimposed views. The background view contains static graphics (circular face of the sensor, numerical legends, labels) that were drawn using paths. The foreground view has graphics for a pointer that needs to be redrawn often. Each widget should probably use a RelativeLayout to contain these child views.
I understand that whenever onDraw () is called for a foreground pointer pointer, then it must be called for the Backgound View that is behind it. Therefore, to optimize the widget redraw time, I tried to use the Canvas drawing cache for the background view. What I did works and leads to a big increase in the speed of redrawing, but the problem is that the cache bitmap that I save and then redraw to Canvas later is never as sharp as what was originally drawn using paths.
The main code that I used in my onDraw () method for the background view:
Bitmap bm = null;
onDraw(Canvas canvas){
if(bm!=null){
Paint bitmapPaint = new Paint();
bitmapPaint.setAntiAlias(false);
bitmapPaint.setFilterBitmap(false);
bitmapPaint.setDither(false);
canvas.drawBitmap(bm, 0, 0, bitmapPaint);
return;
}
... Vector drawing to the Canvas using Path objects happens here,
performed by the SVG converter object ...
setDrawingCacheEnabled(true);
setDrawingCacheQuality(DRAWING_CACHE_QUALITY_HIGH);
bm = Bitmap.createBitmap(getDrawingCache());
}
To try to get the quality of the bitmap as high as possible, I performed the following steps:
Make sure that the cache drawing quality is high.
Paint (bitmapPaint) -, ..
, , () , . , SVG, , SVG . scale() SVG-, canvas.scale(1, 1). / SVG-, Canvas 1,1, .
, : - , , ? , - / , , , .
(, ) - , , , ? , - , , .
; .