468,252 Members | 1,475 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,252 developers. It's quick & easy.

Image resources file *.res extension

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
1 3553
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.

Similar topics

3 posts views Thread by dave | last post: by
reply views Thread by Duncan Welch | last post: by
2 posts views Thread by Don Tucker | last post: by
62 posts views Thread by ivan.leben | last post: by
6 posts views Thread by nichughes | last post: by
6 posts views Thread by Frank Rizzo | last post: by
1 post views Thread by Sinan Alkan | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.