我正在使用带有PaintBox的C ++ Builder作为“可见”图形对象。我有一个用于绘制选择矩形的函数(从onMouseMove事件调用)。对于双重缓冲,我使用Gdiplus :: Bitmap。为了渲染完成的帧,我用PaintBox HDC创建了一个Gdiplus :: Graphics实例,然后通过DrawImage函数在其上绘制位图。
void TMainForm::DrawSelectingRect(int StartX, int StartY, int EndX, int EndY, Gdiplus::Bitmap *CachedBitmap,
Gdiplus::Bitmap *DestBitmap)
{
Gdiplus::Graphics DestGraphics(DestBitmap);
DestGraphics.DrawImage(CachedBitmap, 0, 0);
Gdiplus::Pen Pen(Gdiplus::Color::Silver, 1);
Gdiplus::SolidBrush Brush(Gdiplus::Color::MakeARGB(100, 150, 150, 150));
DestGraphics.FillRectangle(&Brush, (StartX<EndX)*StartX + (EndX<=StartX)*EndX,
(StartY<EndY)*StartY + (EndY<=StartY)*EndY,
abs(EndX - StartX),
abs(EndY - StartY));
DestGraphics.DrawRectangle(&Pen, (StartX<EndX)*StartX + (EndX<=StartX)*EndX,
(StartY<EndY)*StartY + (EndY<=StartY)*EndY,
abs(EndX - StartX),
abs(EndY - StartY));
Gdiplus::Graphics PaintBoxGraphics(MainForm->PaintBox->Canvas->Handle);
PaintBoxGraphics.DrawImage(DestBitmap, 0, 0);
DestGraphics.Flush(Gdiplus::FlushIntentionFlush);
PaintBoxGraphics.Flush(Gdiplus::FlushIntentionFlush);
}
问题在于,与标准VCL TCanvas函数Draw()不同,DrawImage的实现显然并不假定* Image的平滑“复制”(可见如何渲染帧)。因此,我通过创建VCL TBitmap实例并在所有Gdiplus函数中使用其画布并将其最终绘制到PaintBox-> Canvas来解决此问题。 显然,这是一种极其低效的处理方式-是否有另一种解决方法?