// --- Set Bitmap to Memmory -------------------------------------------------
procedure SetBitmap;
var
bmi: BITMAPINFO;
_bmp: tagBITMAP;
pDIB: PDIBSECTION;
dwLen : Cardinal;
p : Pointer;
i: integer;
begin
ZeroMemory(@bmi, sizeof(BITMAPINFO));
with bmi.bmiHeader
do
begin
biSize := SizeOF(BITMAPINFOHEADER);
biWidth := 320;
biHeight := 240;
biPlanes := 1;
biBitCount := 24;
biCompression := BI_RGB;
biSizeImage := biWidth * biHeight * (biBitCount
div 8);
biXPelsPerMeter := 0;
biYPelsPerMeter := 0;
biClrUsed := 0;
biClrImportant := 0;
end;
with bmi.bmiHeader
do
hBMP := CreateDIBSection(hBmpDC, bmi, DIB_RGB_COLORS, p, 0, 0);
// Fill Bitmap
SelectObject(hBmpDC, hBMP);
FillRect(hBmpDC, RECT(0,0,320,240), CreateSolidBrush(
RGB(255,0,0)));
SetBKMode(hBmpDC, TRANSPARENT);
for i := 0
to 100
do
begin
SetTextColor(hBmpDC,
RGB(0, random(256), random(256)) );
TextOut(hBmpDC, random(320-16), random(240-16), '
X', 1);
end;
// Mem action
dwLen := (bmi.bmiHeader.biWidth * bmi.bmiHeader.biHeight);
gMem := GlobalAlloc(GPTR, Sizeof(DIBSECTION) + (dwLen * sizeof(RGBQUAD)));
pDIB := PDIBSECTION(GlobalLock(gMem));
GetObject(hBMP, sizeof(_bmp), @_bmp);
pDIB^.dsBmih := bmi.bmiHeader;
pDIB^.dsBm := _bmp;
pDIB^.dsBm.bmBits := p;
GlobalUnlock(gMem);
p :=
nil;
end;
// --- Get Bitmap from Mem ---------------------------------------------------
procedure GetBitmap;
var
bmi: BITMAPINFO;
pDIB: PDIBSECTION;
bp, p: pointer;
begin
pDIB := PDIBSECTION(GlobalLock(gMem));
bmi.bmiHeader := pDIB^.dsBmih;
bp := pDIB^.dsBm.bmBits;
with bmi.bmiHeader
do
hBMP2 := CreateDIBSection(hBmpDC, bmi, DIB_RGB_COLORS, p, 0, 0);
SetDIBits(hBmpDC, hBMP2, 0, bmi.bmiHeader.biHeight, bp, bmi, DIB_RGB_COLORS);
globalunlock(gMem);
end;