我正在创建一个组件,其中可以通过拖放设计表格。
我设法编写了拖放部分和表格渲染,但是我遇到了问题。
我使用双缓冲来减少闪烁,方法是绘制到内存中的位图,然后将其中的一部分 bitblt 到屏幕上。
脚步:
- 将表格绘制到内存位图(这可能非常大,最多可达最大值)。
- 控制画布上的部分内存位图内容。
问题是,内存中的位图越大,bitblt 操作就越慢(显然)。
我的问题是:
- 如何提高这个性能?我也对替代解决方案感兴趣。
代码:
procedure TCustomGraphicScrollControl.Paint;
var
x,y: Integer;
begin
inherited;
// Rendering is done in the child class. FRender is a 4-bit color depth
// in-memory bitmap.
if HorzScrollBar.Visible then x := HorzScrollBar.Position else x:=0;
if VertScrollBar.Visible then y := VertScrollBar.Position else y:=0;
// We will create a second in-memory bitmap, with the same dimensions as the control
// and the same color depth as FRender. This way BitBlt will be a little faster, as it won't be needed to do any conversion.
// bitblt part of the large in-memory bitmap to screen
BitBlt(
FCanvas.Handle,
0,
0,
Width,
Height,
FRender.Canvas.Handle,
x,
y,
SRCCOPY
);
end;
更新:
从代码和问题中删除了“三重缓冲”和 UpdateScrollBars。