Image resources file *.res extension

D

D. Yates

Hi,

I am looking for an example of how to extract bitmap images from an embedded
resource file (a file with *.res extension, which can be viewed inside of
the ide and can hold bitmaps, icons, string tables, etc.) and place them
into a imagelist.

I have found examples using the resource manager to create a "resource file"
like so:
ResourceWriter rw = new ResourceWriter (
@"D:\Projects\ROG.resources" ) ;
Image img0 = Image.FromFile ( @"D:\Projects\Checked.bmp" ) ;
Image img1 = Image.FromFile ( @"D:\Projects\CheckedDisabled.bmp" )
;
Image img2 = Image.FromFile ( @"D:\Projects\UnChecked.bmp" ) ;
Image img3 = Image.FromFile (
@"D:\Projects\UnCheckedDisabled.bmp" ) ;
rw.AddResource ( "Checked", img0 ) ;
rw.AddResource ( "CheckedDisabled", img1 ) ;
rw.AddResource ( "UnChecked", img2 ) ;
rw.AddResource ( "UnCheckedDisabled", img3 ) ;
rw.Close( ) ;

and then extract the data like so:
Assembly asm = Assembly.GetExecutingAssembly ( ) ;
// Namespace = TestLoadingResourceFile
ResourceManager rm = new ResourceManager (
"TestLoadingResourceFile.ROG", asm ) ;
imageList1.Images.Add( ( Image ) rm.GetObject ( "Checked" ) );
imageList1.Images.Add( ( Image ) rm.GetObject (
"CheckedDisabled" ) );
imageList1.Images.Add( ( Image ) rm.GetObject ( "UnChecked" ) );
imageList1.Images.Add( ( Image ) rm.GetObject (
"UnCheckedDisabled" ) );

// Afterwards add the file in the IDE and change build action to "Embedded
Resource"

This "resource file" cannot be viewed in the IDE as anything other than
binary data unless you change the extension of the file to res. However,
you cannot load the file using the resource manager after viewing the res
file in the IDE because header information is removed from the file when it
is viewed (change extension back to resources and you can see that
information was removed).

Any help will be appreciated.

Thanks,
Dave
 
D

D. Yates

Still no luck finding out how to load data from *.res files, but I did run
across this in MSDN:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconcreatingres
ourcefiles2.htm

Only .resources files should be embedded in common language runtime
assemblies and satellite assemblies. The Resource File Generator
(Resgen.exe) converts text (.txt) files and XML-based resource (.resx) files
into .resources files by wrapping methods implemented by the ResourceReader,
ResourceWriter, ResXResourceReader, and ResXResourceWriter classes. You can
also use Resgen.exe to convert .resources files back into .resx and .txt
files.

However, they are referring to embedding resources inside of "runtime"
assemblies and I am embedding my resources at design time.

In case someone runs across the code below via google this comment is
incorrect:
// Namespace = TestLoadingResourceFile
ResourceManager rm = new ResourceManager ("TestLoadingResourceFile.ROG",
asm ) ;

TestLoadingResourceFile is the name of the namespace, but in the call to
ResourceManager it is the name of the assembly. They just happen to be the
same name.

If you know anything and can give me a hand, I would appreciate it.

Thanks,
Dave


D. Yates said:
Hi,

I am looking for an example of how to extract bitmap images from an embedded
resource file (a file with *.res extension, which can be viewed inside of
the ide and can hold bitmaps, icons, string tables, etc.) and place them
into a imagelist.

I have found examples using the resource manager to create a "resource file"
like so:
ResourceWriter rw = new ResourceWriter (
@"D:\Projects\ROG.resources" ) ;
Image img0 = Image.FromFile ( @"D:\Projects\Checked.bmp" ) ;
Image img1 = Image.FromFile (
@"D:\Projects\CheckedDisabled.bmp" )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top