求双缓冲字幕算法
我现在想实现一个从右向左的滚动字幕代码
我自己做了一些尝试有2个问题解决不了
一个是画面的闪烁问题,另外一个是CPU占用过高影响该软件正在播放的视频程序,使视频程序有停顿。
闪烁问题查了一些资料都是DELPHI的说可以用双缓冲来解决,可是对DELPHI不熟悉希望那位朋友能提供BCB代码谢谢。
[解决办法]
在TPaintBox上重画 TPaintBox *pbSbtt; TLabel *lblSbtt;
try
{
HDC hdcCompatible = CreateCompatibleDC(pbSbtt-> Canvas-> Handle);
// Create a compatible bitmap for hdcScreen.
HBITMAP hbmScreen = CreateCompatibleBitmap(pbSbtt-> Canvas-> Handle,
GetDeviceCaps(pbSbtt-> Canvas-> Handle, HORZRES),
GetDeviceCaps(pbSbtt-> Canvas-> Handle, VERTRES));
if (!SelectObject(hdcCompatible, hbmScreen))
{
return;
}
SetBkMode(hdcCompatible, OPAQUE);
RECT ImgRect;
ImgRect.left = 0;
ImgRect.top = 0;
ImgRect.right = pbSbtt-> Width;
ImgRect.bottom = pbSbtt-> Height;
pbSbtt-> Canvas-> Brush-> Color = pbSbtt-> Color;
FillRect(hdcCompatible, &ImgRect, (HBRUSH)pbSbtt-> Canvas-> Brush-> Handle);
RECT lblRect;
lblRect.left = lblSbtt-> Left;
lblRect.top = lblSbtt-> Top;
lblRect.right = lblSbtt-> Left + lblSbtt-> Width;
lblRect.bottom = lblSbtt-> Top + lblSbtt-> Height;
SelectObject(hdcCompatible, (HBRUSH)pbSbtt-> Canvas-> Brush-> Handle);
SelectObject(hdcCompatible, (HFONT)lblSbtt-> Font-> Handle);
SetBkColor(hdcCompatible, (COLORREF)pbSbtt-> Color);
SetTextColor(hdcCompatible, (COLORREF)lblSbtt-> Font-> Color);
DrawText(hdcCompatible, lblSbtt-> Caption.c_str(), -1, &lblRect, DT_SINGLELINE | DT_NOPREFIX);
if (!BitBlt(pbSbtt-> Canvas-> Handle,
0, 0,
pbSbtt-> Width, pbSbtt-> Height,
hdcCompatible,
0, 0,
SRCCOPY))
{
}
DeleteDC(hdcCompatible);
DeleteObject(hbmScreen);
}
catch(...)
{
}
希望对你有用!