Solved

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

Posted on 2001-09-03
20
166 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

9 Experts available now in Live!

Get 1:1 Help Now