type TRGBALine = array[word] of TRGBQuad; PRGBALine = ^TRGBALine; function IconToBitmap(const IconHandle: HIcon):TBitmap; var IcoInfo: TIconInfo; mask: TBitmap; x, y: word; begin result := nil; if NOT GetIconInfo(IconHandle, IcoInfo) then exit; try try result := TBitmap.Create; result.Handle := IcoInfo.hbmColor; result.PixelFormat := pf32bit; mask := TBitmap.Create; mask.Handle := IcoInfo.hbmMask; mask.PixelFormat := pf32bit; for x := 0 to result.Width-1 do for y := 0 to result.Height-1 do pRGBALine(result.Scanline[y])^[x].rgbReserved := NOT pRGBALine(mask.Scanline[y])^[x].rgbRed; except FreeAndNil(result); end; finally if Assigned(mask) then mask.Free; end; end;
위 함수를 사용할때는 아래와 같이 사용한다.
procedure TForm1.Button1Click(Sender: TObject);
var
IconHandle: HIcon;
Bitmap: TBitmap;
begin
IconHandle := LoadIcon(HInstance, 'MAINICON');
if ( IconHandle <> 0 ) then
begin
Bitmap := IconToBitmap( IconHandle );
if Bitmap <> nil then
begin
SaveToFile('C:\MAINICON.bmp');
Free;
end;
end;
end;




