Solved

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

Posted on 2001-09-03
20
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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