首页  编辑  

bmp->ico

Tags: /超级猛料/Picture.图形图像编程/图片转换/   Date Created:

关于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;

---------------------------------------

procedure BmpToIco(ABmp,AIco:string);

var

 bmp,mbmp:tbitmap;

 ico:ticon;

 rbmp:BITMAP;

 a:array[0..4096] of byte;

 len:dword;

 i:integer;

 imglist:timagelist;

begin

 bmp:=tbitmap.Create;

 mbmp:=tbitmap.Create;

 mbmp.Assign(bmp);

 ico:=ticon.Create;

 imglist:=TImageList.CreateSize(32,32);

 try

   bmp.LoadFromFile(abmp);

   len:=GetBitmapBits(bmp.Handle,4096,@a);

   mbmp.Handle:=CreateBitmapIndirect(rbmp);

   for i:=0 to len do

     a[i]:=a[i] and a[i];

   SetBitmapBits(bmp.Handle,len,@a);

   imglist.add(bmp,mbmp);

   imglist.GetIcon(0,ico);

 finally

   bmp.Free;

   ico.Free;

   imglist.Free;

 end;

end;