I am making an oscilloscope in android. So far I have made the base axis, this axis are drawn each time the program starts. Now I want to make the performance a bit better by saving the axis canvas after the first time that it is created. My idea is to save this canvas as a bitmap and recall it next times:
public class ScopeCanvas : View
{
private Context _context;
public double TimeBase { get; set; }
public double VoltagePerDiv { get; set; }
private Canvas _axisCanvas;
private Bitmap _savedAxisCanvas;
/// <summary>
/// Constructor
/// </summary>
/// <param name="context">Context</param>
public ScopeCanvas(Context context, double timeBase, double voltagePerDiv) : base(context)
{
_context = context;
TimeBase = timeBase;
VoltagePerDiv = voltagePerDiv;
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
if(_axisCanvas == null)
{
_axisCanvas = CreateAxis(canvas);
#if DEBUG
Console.WriteLine("Axis canvas newly created!");
#endif
}
else
{
#if DEBUG
Console.WriteLine("Using pre made axis canvas!");
#endif
}
}
}
Can somone pleae tell me how can I save this canvas and recall it later? I mean in the OnDraw event!
P.S: CreateAxis(canvas) is the method that I draw the axis on it. This is how it looks:

Since I dont want to hard code a fixed distance between voltage and time base division, this need to be drawn dynamicly atleast the first time it creates (resoloution independent) using things like ExactCenterY and etc…
you “could” reference it to a member-variable, but this won’t be a good idea.
If you want to draw later on that canvas, try to invalidate your view (again) so that the
onDraw()method is called again and you can use the given canvas.