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
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