function BitmapToImage(Hdib: HBitmap): Pointer;
var
lpImg: Pointer;
bi: tagBITMAPINFO;
bm: Bitmap;
BitmapLength: LongWord;
bmpBits: TBytes;
DC: HDC;
begin
Result :=
nil;
DC := GetDc(0);
if Hdib <> 0
then
begin
GetObject(Hdib, sizeof(bm), @bm);
bi.bmiHeader.biSize := SIZEOF(bi.bmiHeader);
bi.bmiHeader.biWidth := bm.bmWidth;
bi.bmiHeader.biHeight := -bm.bmHeight;
bi.bmiHeader.biPlanes := 1;
bi.bmiHeader.biBitCount := 32;
bi.bmiHeader.biCompression := BI_RGB;
BitmapLength := bm.bmWidth * bm.bmHeight * 4;
SetLength(bmpBits, BitmapLength + 1);
GetDIBits(
DC, Hdib, 0, bm.bmHeight, @bmpBits[0], bi, DIB_RGB_COLORS);
if @bmpBits[0] <>
nil then
begin
if Gdip_CreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidth * 4, PixelFormat32bppARGB,
@bmpBits[0], lpImg) = OK
then
Result := lpImg;
end;
ReleaseDC(0,
DC);
end;
end;