Animating a Palette
[The feature associated with this page, DrawDib, is a legacy feature. It has been superseded by MediaComposition class. MediaComposition class has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaComposition class instead of DrawDib, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
The following example animates a palette by using the DrawDibRealize, DrawDibChangePalette, and DrawDibDraw functions.
You can change the colors of a bitmap by using the DrawDibBegin function in combination with DrawDibChangePalette. First, to allow palette changes, specify the DDF_ANIMATE flag in the call to DrawDibBegin. Second, set the color table values from the palette entries by using DrawDibChangePalette.
For example, if lppe is an address of the PALETTEENTRY array containing the new colors, and lpbi is the BITMAPINFOHEADER structure used in DrawDibBegin or DrawDibDraw, the following fragment updates the DIB color table.
hdc = GetDC(hwnd);
DrawDibBegin(hdd, ....., DDF_ANIMATE);
DrawDibRealize(hdd, hdc, fBackground);
DrawDibDraw(hdd, hdc, ...., DDF_SAME_DRAW|DDF_SAME_HDC);
// Call to change color.
DrawDibChangePalette(hDD, iStart, iLen, lppe);
.
.
.
ReleaseDC(hwnd, hdc);
Related topics