一个资源文件里的ICO问题!会的简单,我不会郁闷了好久. ( 积分: 100 )

  • 主题发起人 主题发起人 xebaobei
  • 开始时间 开始时间
X

xebaobei

Unregistered / Unconfirmed
GUEST, unregistred user!
我编译了个资源文件.<br>--Asui_parse.rc-----------------<br>big ICON big.ico<br>small ICON small.ico<br>--------------------------------<br>Brcc32 Asui_parse.rc<br><br>成功编译出 Asui_parse.RES<br>用DELPHI自带的 imagedit 成功打开! 两个图标确实为一大一小!<br>一个32*32 一个16*16<br><br>但是我用我的代码一读 居然全是32*32的!<br>var<br>bigico,smallico:ticon;<br>begin<br>bigico:=ticon.Create;<br>smallico:=ticon.Create;<br><br>bigico.Handle:=LoadIcon(hinstance,'big');<br>smallico.Handle:=LoadIcon(hinstance,'small');<br><br>bigico.SaveToFile('c:/big.ico');<br>smallico.SaveToFile('c:/small.ico');<br><br>bigico.Free;<br>smallico.Free;<br><br>保存到C盘的两个文件全是32*32的!
 
我编译了个资源文件.<br>--Asui_parse.rc-----------------<br>big ICON big.ico<br>small ICON small.ico<br>--------------------------------<br>Brcc32 Asui_parse.rc<br><br>成功编译出 Asui_parse.RES<br>用DELPHI自带的 imagedit 成功打开! 两个图标确实为一大一小!<br>一个32*32 一个16*16<br><br>但是我用我的代码一读 居然全是32*32的!<br>var<br>bigico,smallico:ticon;<br>begin<br>bigico:=ticon.Create;<br>smallico:=ticon.Create;<br><br>bigico.Handle:=LoadIcon(hinstance,'big');<br>smallico.Handle:=LoadIcon(hinstance,'small');<br><br>bigico.SaveToFile('c:/big.ico');<br>smallico.SaveToFile('c:/small.ico');<br><br>bigico.Free;<br>smallico.Free;<br><br>保存到C盘的两个文件全是32*32的!
 
富翁们<br>一定要帮忙啊!
 
//Asui_parse.rc文件(你编译得没错)编译后的asui_parse.RES文件放在程序文件夹下<br>big ICON big.ico<br>small ICON small.ico<br><br>//主程序<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>{$R Asui_parse.RES}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;bigico, smallico: ticon;<br>begin<br> &nbsp;bigico := ticon.Create;<br> &nbsp;smallico := ticon.Create;<br><br> &nbsp;bigico.Handle := LoadIcon(hinstance, 'big');<br> &nbsp;smallico.Handle := LoadIcon(hinstance, 'small');<br><br> &nbsp;bigico.SaveToFile('c:/big.ico');<br> &nbsp;smallico.SaveToFile('c:/small.ico');<br><br> &nbsp;bigico.Free;<br> &nbsp;smallico.Free;<br>end;<br><br>end.<br>//成功
 
指定下icon的大小看看。
 
我可以得到ICO文件<br>但是全是32*32的!<br>而我的资源文件里是一个32*32 一个16*16<br>你得到难道是一个32*32 一个16*16?
 
Cannot change then size of an icon<br>改变不了.
 
height,width.
 
就是 height,width.改不了
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=583151<br><br>自己翻下以前的帖子就不完了。非让别人帮你找。用SHGetFileInfo函数。<br>具体方法看&quot;omvm&quot;的回帖
 
抱歉有没有简单点的<br>写的太麻烦了<br>而且好象也不是在直接取自己的资源文件里的.
 
汗。我尝试了一下,如下:<br><br> PCursorOrIcon = ^TCursorOrIcon;<br> &nbsp;TCursorOrIcon = packed record<br> &nbsp; &nbsp;Reserved: Word;<br> &nbsp; &nbsp;wType: Word;<br> &nbsp; &nbsp;Count: Word;<br> &nbsp;end;<br>//This has been defined in DELPHI9. But not the definition of IconEntry.<br> PIconEntry = ^TIconEntry;<br> TIconEntry= packed record<br> &nbsp; bWidth : Byte; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Width, in pixels, of the image<br> &nbsp; bHeight : Byte; &nbsp; &nbsp; &nbsp; &nbsp; // Height, in pixels, of the image<br> &nbsp; bColorCount: Byte; &nbsp; &nbsp; // Number of colors in image (0 if &gt;=8bpp)<br> &nbsp; bReserved: Byte; &nbsp; &nbsp; &nbsp; // Reserved ( must be 0)<br> &nbsp; wPlanes : word; &nbsp; &nbsp; &nbsp; &nbsp; // Color Planes<br> &nbsp; wBitCount : word; &nbsp; &nbsp; &nbsp; // Bits per pixel<br> &nbsp; dwBytesInRes : dword; &nbsp; &nbsp;// How many bytes in this resource?<br> &nbsp; dwImageOffset : dword;<br> end;<br><br>var<br> hRes,hMem:HRSRC;<br> lpMem : Pointer;<br> lp1 : PBYTE;<br> n : integer;<br> ts : TMemoryStream;<br> IconHeader : TCursorOrIcon;<br> IconEntry : TIconEntry;<br><br>begin<br> ts:=TMemoryStream.Create;<br> hRes:=FindResource(hInstance,'small',rt_group_icon);<br> hMem:=LoadResource(hInstance,hRes);<br> lpMem:=LockResource(hMem);<br> IconHeader.Reserved:=PWord(lpMem)^; //usually be $0.<br> IconHeader.wType:=$01; //$01 for ICON<br> IconHeader.Count:=$01; // we just want lookup a single icon.<br> //ts.Write(pbyte(lpMem)^,sizeof(TCursorOrIcon));<br> ts.Write(IconHeader,sizeof(IconHeader));<br><br> n := LookUpIconIDFromDirectoryEx(PBYTE(lpMem),True,16,SM_CYSMICON,LR_DEFAULTCOLOR);<br> hRes:=FindResource(hInstance,MakeIntResource(n),rt_icon);<br> hMem:=LoadResource(hInstance,hRes);<br> lpMem:=LockResource(hMem);<br><br> IconEntry.bWidth:= TBitmapInfoHeader(lpMem^).biWidth;<br> IconEntry.bHeight:=TBitmapInfoHeader(lpMem^).biHeight div 2;<br> n:=TBitmapInfoHeader(lpMem^).biPlanes * TBitmapInfoHeader(lpMem^).biBitCount;<br> if n&gt;=8 then IconEntry.bColorCount:=0<br> else IconEntry.bColorCount:= 1 shl n;<br><br> IconEntry.bReserved:=$0;<br> IconEntry.wBitCount:=TBitmapInfoHeader(lpMem^).biBitCount;<br> IconEntry.wPlanes:=TBitmapInfoHeader(lpMem^).biPlanes;<br> IconEntry.dwBytesInRes:= sizeofResource(hInstance,hRes);<br> IconEntry.dwImageOffset:=sizeof(TCursorOrIcon)+sizeof(TIconEntry);<br><br> ts.Write(IconEntry,sizeof(IconEntry));<br> ts.Write(pbyte(lpMem)^,IconEntry.dwBytesInRes);<br> ts.SaveToFile('test.ico');<br> ts.Free;<br>end;
 
LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use the LoadImage function to load icons of other sizes.<br>这是MSDN的信息。请使用LoadImage/ExtractIconEx
 
后退
顶部