PDA

View Full Version : PNG -> RES



cairnswm
21-09-2006, 01:10 PM
How do I put a PNG image into a Resource File?

grudzio
21-09-2006, 02:10 PM
Try using editors like Resource Hacker (http://www.angusj.com/resourcehacker/) or
Resource Editor (http://www.wilsonc.demon.co.uk/d10resourceeditor.htm).

cairnswm
21-09-2006, 02:19 PM
Neither of them has PNG support

savage
21-09-2006, 03:22 PM
You need to create an *.rc file and then compile it into a *.res file
*.rc files look similar to this...



BagOMoneyGif 23 "BagOMoney.gif"
GenericWebViewCss 23 "GenericWebView.css"
zSorterVerifier 14 "Closer48.ico"
zSQLWait CURSOR "SQLWait.cur"
ReportLogo BITMAP "ReportLogo.bmp"
ProgressThreadAVI AVI "ProgressThread.avi"
zContentPanelTemplate 23 "ContentPanel.htt"
ControlPanelhtm 23 "ControlPanel.html"
Backgroundjpg 23 "Background.jpg"
PrimaryPNG RCDATA Primary.png


First comes the ResourceName, then ResourceType and finally quoted path to the resource on your HD.

As you can see you can pretty much embed anything you like into a resource file.

Depending on the version of Delphi you are using you can either add the rc to the project and it will automatically compile it into a .res file and embed it or alternatively you can Use brcc.exe to compile the resouce:

C:\{PATH TO DELPHI}\bin\brcc.exe MyResources.rc

Then put

{$R MyResources.Res}

in either your .dpr file or the unit where you plan to use it.

The next step is to load the resources. Look into FindResource() and LoadResource() WinAPIs on Google groups.

grudzio
21-09-2006, 03:34 PM
How about those two: resource tuner (http://www.restuner.com/)
and PE explorer (http://www.batchconverter.com/PEExplorer-download-9498.shtml).
They are not freeware but have trial version. If they are no good, the only way I see is to add png file manually i.e. make Your own png resource editor. The resource editor I've mentioned in post above comes with the source code, so You will have a starting point. Or You can make your own resource file. Ther is an article how to make custom resource file and how to add to .exe on http://www.delphi3000.com in games section. Unfortunatelly I cant help You more. :(

technomage
21-09-2006, 10:06 PM
This brings up a question I have always wanted to know. How to compile resources into a linux binary using freepascal :?: :?:

Anyone got any ideas :?:

grudzio
22-09-2006, 03:37 PM
How to compile resources into a linux binary using freepascal :?: :?:

Anyone got any ideas :?:

This is from the FPC documentation (Programmers's manuall):



$R or $RESOURCE : Include resource

This directive includes a resource in the binary. The argument to this directive is the resource to include:
{$R icons.res}

Will include the file icons.res as a resource in the binary. Currently resources are supported only for Windows (native resources are used) and for platforms using ELF binaries (linux, BSD).

The asterix can be used as a placeholder for the current unit/program filename:
unit myunit;
{$R *.res}

will include myunit.res.



There is a TResourceStream class so (in theory) it is possible to load resource. But I don't know how to make .res files on Linux. Maybe Lazarus has utility for this?

Finally if someone is interested how to read/write custom data from/to Linux/Windows executable, the ]here[/url].
Much better then the previous one I gave.

marmin
11-10-2006, 02:21 AM
use 'windres' on Linux to create a resource file. it's in binutils.