我正在使用带有C#的.Net Compact Framework 2.0 SP2开发Windows Mobile 5.0 及更高版本的应用程序。
我在自定义消息框上重写 OnPaint 方法,该消息框绘制了一个位图,该位图用 alpha 透明度填充整个表单,以及一个带有按钮的渐变框和半透明背景上的消息。
我正在测试它,但它太慢了,所以我将使用双缓冲。我可以使用双缓冲区来绘制渐变框和测试,但如果我使用带有 alpha 透明度的背景位图的双缓冲区,它不会绘制 alpha 透明度。所以我只用渐变框和消息和按钮做双缓冲。免费的透明位图直接绘制在 e.Graphics 上。
我想知道是否可以将 e.Graphics 保存在位图上以完成所有工作并结束 OnPaint 方法绘制到 e.Graphics 这个我之前保存的位图。
这是我的代码:
protected override void OnPaint(PaintEventArgs e)
{
Graphics gxOff;
gxOff = Graphics.FromImage(bmpOffscreen);
if (!isOuterBackgroundPainted)
{
isOuterBackgroundPainted = true;
DrawingHelper.DrawAlpha(e.Graphics, outerBackground, 180, 0, 0);
// Here I don't use double buffer because Alpha Blend doesn't work with double buffer.
//DrawingHelper.DrawAlpha(gxOff, outerBackground, 180, 0, 0);
}
// Draw the gradient box
GradientFill.Fill(gxOff, rectangle, startColor, endColor, FillDirection.TopToBottom);
gxOff.DrawString(message, font, brush, textLayoutRectangle);
e.Graphics.DrawImage(bmpOffscreen, 10, 10);
base.OnPaint(e);
}
bmpOffscreen:双缓冲区的位图。
也许我可以在 bmpOffscreen 中获取表单的快照,然后在其上绘制半透明背景、渐变框和文本。
总结: 我想将 alpha blend 与 double buffer 一起使用。
有什么建议吗?