首先声明一个ticon变量,然后在转换,用了draw方法,很简单的饿你自己试史

解决方案 »

  1.   

    You must create two bitmaps, a mask bitmap (called the "AND"
    bitmap) and a image bitmap (called the XOR bitmap). You can pass the
    handles to the "AND" and "XOR"  bitmaps to the Windows API function
    CreateIconIndirect() and use the returned icon handle in your
    application.Example:procedure TForm1.Button1Click(Sender: TObject);
    var
      IconSizeX : integer;
      IconSizeY : integer;
      AndMask : TBitmap;
      XOrMask : TBitmap;
      IconInfo : TIconInfo;
      Icon : TIcon;
    begin
     {Get the icon size}
      IconSizeX := GetSystemMetrics(SM_CXICON);
      IconSizeY := GetSystemMetrics(SM_CYICON); {Create the "And" mask}
      AndMask := TBitmap.Create;
      AndMask.Monochrome := true;
      AndMask.Width := IconSizeX;
      AndMask.Height := IconSizeY; {Draw on the "And" mask}
      AndMask.Canvas.Brush.Color := clWhite;
      AndMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
      AndMask.Canvas.Brush.Color := clBlack;
      AndMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4); {Draw as a test}
      Form1.Canvas.Draw(IconSizeX * 2, IconSizeY, AndMask); {Create the "XOr" mask}
      XOrMask := TBitmap.Create;
      XOrMask.Width := IconSizeX;
      XOrMask.Height := IconSizeY; {Draw on the "XOr" mask}
      XOrMask.Canvas.Brush.Color := ClBlack;
      XOrMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
      XOrMask.Canvas.Pen.Color := clRed;
      XOrMask.Canvas.Brush.Color := clRed;
      XOrMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4); {Draw as a test}
      Form1.Canvas.Draw(IconSizeX * 4, IconSizeY, XOrMask); {Create a icon}
      Icon := TIcon.Create;
      IconInfo.fIcon := true;
      IconInfo.xHotspot := 0;
      IconInfo.yHotspot := 0;
      IconInfo.hbmMask := AndMask.Handle;
      IconInfo.hbmColor := XOrMask.Handle;
      Icon.Handle := CreateIconIndirect(IconInfo); {Destroy the temporary bitmaps}
      AndMask.Free;
      XOrMask.Free; {Draw as a test}
      Form1.Canvas.Draw(IconSizeX * 6, IconSizeY, Icon); {Assign the application icon}
      Application.Icon := Icon; {Force a repaint}
      InvalidateRect(Application.Handle, nil, true); {Free the icon}
      Icon.Free;
    end;You must create two bitmaps, a mask bitmap (called the "AND"
    bitmap) and a image bitmap (called the XOR bitmap). You can pass the
    handles to the "AND" and "XOR"  bitmaps to the Windows API function
    CreateIconIndirect() and use the returned icon handle in your
    application.Example:procedure TForm1.Button1Click(Sender: TObject);
    var
      IconSizeX : integer;
      IconSizeY : integer;
      AndMask : TBitmap;
      XOrMask : TBitmap;
      IconInfo : TIconInfo;
      Icon : TIcon;
    begin
     {Get the icon size}
      IconSizeX := GetSystemMetrics(SM_CXICON);
      IconSizeY := GetSystemMetrics(SM_CYICON); {Create the "And" mask}
      AndMask := TBitmap.Create;
      AndMask.Monochrome := true;
      AndMask.Width := IconSizeX;
      AndMask.Height := IconSizeY; {Draw on the "And" mask}
      AndMask.Canvas.Brush.Color := clWhite;
      AndMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
      AndMask.Canvas.Brush.Color := clBlack;
      AndMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4); {Draw as a test}
      Form1.Canvas.Draw(IconSizeX * 2, IconSizeY, AndMask); {Create the "XOr" mask}
      XOrMask := TBitmap.Create;
      XOrMask.Width := IconSizeX;
      XOrMask.Height := IconSizeY; {Draw on the "XOr" mask}
      XOrMask.Canvas.Brush.Color := ClBlack;
      XOrMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
      XOrMask.Canvas.Pen.Color := clRed;
      XOrMask.Canvas.Brush.Color := clRed;
      XOrMask.Canvas.Ellipse(4, 4, IconSizeX - 4, IconSizeY - 4); {Draw as a test}
      Form1.Canvas.Draw(IconSizeX * 4, IconSizeY, XOrMask); {Create a icon}
      Icon := TIcon.Create;
      IconInfo.fIcon := true;
      IconInfo.xHotspot := 0;
      IconInfo.yHotspot := 0;
      IconInfo.hbmMask := AndMask.Handle;
      IconInfo.hbmColor := XOrMask.Handle;
      Icon.Handle := CreateIconIndirect(IconInfo); {Destroy the temporary bitmaps}
      AndMask.Free;
      XOrMask.Free; {Draw as a test}
      Form1.Canvas.Draw(IconSizeX * 6, IconSizeY, Icon); {Assign the application icon}
      Application.Icon := Icon; {Force a repaint}
      InvalidateRect(Application.Handle, nil, true); {Free the icon}
      Icon.Free;
    end;把位图转换成.ico
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      TheIcon : TIcon;
      TheBitmap : TBitmap;
    begin
      TheIcon := TIcon.Create;
      TheIcon.LoadFromFile('C:\Program Files\Borland\IcoCur32\EARTH.ICO');
      TheBitmap := TBitmap.Create;
      TheBitmap.Height := TheIcon.Height;
      TheBitmap.Width := TheIcon.Width;
      TheBitmap.Canvas.Draw(0, 0, TheIcon);
      Form1.Canvas.Draw(10, 10, TheBitmap);
      TheBitmap.Free;
      TheIcon.Free;
    end;
    把.ico转换为.bmp