function BmpToIco(mBitmap: TBitmap; mIcon: TIcon;
  mSize32: Boolean = True): Boolean;
var
  vIconWidth: Integer;
  vIconHeight: Integer;
  vBitmapMask: TBitmap;
  vBitmapColor: TBitmap;
  vIconInfo: TIconInfo;
begin
  Result := True;
  if mSize32 then begin
    vIconWidth := 32;
    vIconHeight := 32;
  end else begin
    vIconWidth := 16;
    vIconHeight := 16;
  end;  vBitmapMask := TBitmap.Create;
  vBitmapColor := TBitmap.Create;
  try
    vBitmapMask.Width := vIconWidth;
    vBitmapMask.Height := vIconHeight;
    vBitmapMask.Canvas.Brush.Color := clBlack;
    vBitmapMask.Canvas.Rectangle(0, 0, vIconWidth, vIconHeight);    vBitmapColor.Width := vIconWidth;
    vBitmapColor.Height := vIconHeight;
    StretchBlt(vBitmapColor.Canvas.Handle, 0, 0, vIconWidth, vIconHeight,
      mBitmap.Canvas.Handle, 0, 0, mBitmap.Width, mBitmap.Height, SRCCOPY);    vIconInfo.fIcon := True;
    vIconInfo.xHotspot := 0;
    vIconInfo.yHotspot := 0;
    vIconInfo.hbmMask := vBitmapMask.Handle;
    vIconInfo.hbmColor := vBitmapColor.Handle;
    mIcon.Handle := CreateIconIndirect(vIconInfo);
  except
    Result := False;
  end;
  vBitmapMask.Free;
  vBitmapColor.Free;
end; { BmpToIco }

解决方案 »

  1.   

    关于ICO转换我些过一段代码(bmp->ico),贴给你,希望有用。if(hBit == NULL) // hBit is BitMap Handle
    return NULL;CBitmap oBitmap;
    oBitmap.Attach(hBit);CBitmap oBMap;
    BITMAP rBitMap;
    oBitmap.GetBitmap( &rBitMap );
    oBMap.CreateBitmapIndirect( &rBitMap );
    BYTE a[4096];
    DWORD len = oBitmap.GetBitmapBits (4096,a);
    for (UINT i=0; i<len; i++)
    {
    a[i] ^= a[i];
    }
    oBMap.SetBitmapBits( len, a);HICON hIcon;
    if (bTheBigIcon)
    {
    CImageList oImagelist;
    oImagelist.Create(32, 32, TRUE, 1, 1);
    oImagelist.Add(&oBitmap, &oBMap);hIcon = oImagelist.ExtractIcon( 0 );
    oImagelist.DeleteImageList();
    }
    else
    {
    CImageList oImagelist;
    oImagelist.Create(16, 16, TRUE, 1, 1);
    oImagelist.Add(&oBitmap, &oBMap);hIcon = oImagelist.ExtractIcon( 0 );
    oImagelist.DeleteImageList();
    }
    m_bIcon = false;
    return hIcon;