Solved

need an image tool to extract bitmap resources from Windows files.

Posted on 2001-09-03
20
167 Views
Last Modified: 2010-04-06
Hi all,
I need an image tool to extract bitmap resources from Windows files. When I choose a directory or driver, it must can extract all the bmps/icons from this directory or the driver.

Thanks, supwang
0
Comment
Question by:SupWang
20 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 6452297
You may want to take a look at jcl. (JEDI code library)

http://www.delphi-jedi.org/Jedi:CODELIBJCL:21737

There is a unit inside jclPeImage.pas

It can get anything from a PE file. EXE DLL DRV etc.

Regards Jacco.
0
 
LVL 2

Author Comment

by:SupWang
ID: 6452340
Hi Jacco,
It seems that the "JCL" just for D4/D5, but I am using D3.
I dont need the source. just need a image tool.
I find many image tools in here: http://www.torry.net/tools_imagetools.htm

But I dont know which can extract all the bmps/icons from a directory or a driver.

Regards, supwang
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6452760
Hi, Supwang.

Thanks for great idea. I spend many times looking for icons.

So, it's a code:

Const
 IconN : Integer = 0;
 BmpN  : Integer = 0;


function SaveResource(hModule : THandle; lpszType : PChar;
                      lpszName : PChar;  lParam   : Integer) : Boolean; stdcall;
Var
 Dst   : String;
 HI    : HIcon;
 Info  : TIconInfo;
Begin
 Result := True;

 Dst := PChar(lParam);

 If (lpszType = RT_BITMAP) Then Begin
  With TBitmap.Create Do Begin
   Try
    Handle := LoadBitmap(hModule, lpszName);
    SaveToFile(Dst + Format('Bmp%d.bmp', [BmpN]));
    Inc(BmpN);
   finally
    Handle := 0;
    Free;
   end;
  End;
 End;

 If (lpszType = RT_GROUP_ICON) Then Begin
  With TIcon.Create Do Begin
   Try
    HI := LoadIcon(hModule, lpszName);
    If GetIconInfo(HI, Info) and Info.fIcon Then Begin
     Handle := HI;
     SaveToFile(Dst + Format('Icon%d.ico', [IconN]));
    End;
    Inc(IconN);
//    Free;
   except
   end;
   Free;
  End;
 End;

End;

procedure ExtractIconsFromFile(AFile, Dst : String);
Var
 Lib : THandle;
Begin
 Lib := LoadLibraryEx(PChar(AFile), 0, LOAD_LIBRARY_AS_DATAFILE);
 If Lib = 0 Then Exit;
 Try
  EnumResourceNames(Lib, RT_BITMAP, @SaveResource, Integer(Dst));

  EnumResourceNames(Lib, RT_GROUP_ICON, @SaveResource, Integer(Dst));


 finally
  FreeLibrary(Lib);
 end;
End;

procedure ExtractIconsFromFolder(Src, Dst : String);
Var
 Rec : TSearchRec;
 Res : Integer;
 Ext : String;
Begin
 If Src[Length(Src)] <> '\' Then
  Src := Src + '\';

 If Dst[Length(Dst)] <> '\' Then
  Dst := Dst + '\';

 Res := FindFirst(Src + '*.*', faAnyFile, Rec);
 Try
  While Res = 0 Do Begin
   Application.ProcessMessages;

   If Rec.Name[1] = '.' Then Begin
    Res := FindNext(Rec);
    Continue;
   End;

   If (faDirectory and Rec.Attr) <> 0 Then
    ExtractIconsFromFolder(Src + Rec.Name, Dst)

   Else Begin
    Ext := LowerCase(ExtractFileExt(Rec.Name));

    If (Ext = '.ico') Then Begin
     CopyFile(PChar(Src + Rec.Name), PChar(Dst + Format('Icon%d.ico', [IconN])), False);
     Inc(IconN);
    End;

    If (Ext = '.bmp') Then Begin
     CopyFile(PChar(Src + Rec.Name), PChar(Dst + Format('Bmp%d.bmp', [BmpN])), False);
     Inc(BmpN);
    End;

    If (Ext = '.dll') or (Ext = '.exe') Then
     ExtractIconsFromFile(Src + Rec.Name, Dst);
   End;

   Res := FindNext(Rec);
  End;
 finally
  FindClose(Rec);
 end;
End;

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


procedure TForm1.Button1Click(Sender: TObject);
begin
 ExtractIconsFromFolder('C:\Windows', 'C:\Icons');
end;


There are some problems with extracting icons (sometimes it raise errors). I comment "Free" method, and it have memory leak. But the function should be in small console application that closed after the function (I good enough for me :) )

0
 
LVL 2

Author Comment

by:SupWang
ID: 6469351
Hi Slavak,
Thanks.  :-)
But why I extract 9500 bitmaps from "Program Files", have 8000 bitmaps is 0 bytes file?

Thanks, supwang
0
 
LVL 2

Author Comment

by:SupWang
ID: 6473347
Hi Slavak,
I try to extract bmps/icons from "c:\Program Files\Borland\Delphi 3\Bin" and  "c:\Program Files\Borland\Delphi4\Bin", but just get some 0 size files.

Regards, supwang
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6474018
Hi,

I tried it on C:\Program files and get 3113 not empty files. I did in on Win2K system using Delphi  5. In debugger I sometimes get exception "Bitmap image not valid" for icons. It happends in SaveToFile function. Maybe ver. 3,4 of Delphi opens a file before check the image.
0
 
LVL 2

Author Comment

by:SupWang
ID: 6474119
Hi Slavak,
I am using D3 + win98.  :-(  more ideas?

Regards, supwang
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6474203
Run it in debugger :), I have not D3, so cannot check it, sorry.
0
 
LVL 2

Author Comment

by:SupWang
ID: 6474248
Hi Slavak,
Can you send me the exe files?
Put two edit components on the form. one is source path, another is target path.
my email is addsup@163.net

Thanks, supwang
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6474775
done
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Slavak
ID: 6474851
done
0
 
LVL 2

Author Comment

by:SupWang
ID: 6474856
Hi Slavak,
I use your program and try this path "c:\Program Files\Borland\Delphi 3\BIN", get all the 0 size bmp files.

and try "c:\Program Files\Borland\Delphi4", all 0 size bmp files.

Regards, supwang
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6474870
Hi,

I don't know what a problem. On my computer it works. If files is '.bmp' or '.ico' then I just copy them, so I have not idea why at your computer all files with 0 length :(

Regards
0
 
LVL 2

Author Comment

by:SupWang
ID: 6474895
Don't know, I had already tried it on two computers. :-(
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6474921
Did you tried to run it from IDE?
0
 
LVL 2

Author Comment

by:SupWang
ID: 6476499
Now I try it at IDE three times, but the result as same as using your exe files.

Regards, supwang
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6476651
Did you get any exceptions?
0
 
LVL 2

Author Comment

by:SupWang
ID: 6476762
Yes, After I extract 13,020 bmp files from "C:", (But 12,544 files is 0 size)  the IDE show me a error message.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9294187
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQed and points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9374197
PAQed per request/recommendation & Points refunded

YensidMod
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now