By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,806 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,806 IT Pros & Developers. It's quick & easy.

Image resources file *.res extension

P: n/a
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

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <fo****@hotmail.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
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


Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.