我正在用android制作示波器。到目前为止,我已经制作了基轴,每次程序启动时都会绘制这个轴。现在我想通过在第一次创建轴画布后保存它来提高性能。我的想法是将此画布保存为位图并在下次调用:
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
}
}
}
有人能告诉我如何保存这幅画布并稍后再回忆吗?我的意思是在OnDraw
活动中!
PS:CreateAxis(canvas)
是我在上面画轴的方法。这是它的外观:
由于我不想硬编码电压和时基划分之间的固定距离,因此需要至少在第一次使用 ExactCenterY 等创建(与分辨率无关)时动态绘制它......