Resource Files & Image Extraction Help Win[C#]

M

MikeY

I'm having trouble extaction my image from my resource file using
DictionaryEnumerator & ResourceReader. String extractions are good.

I've been trying to look online for exact info on this, but alas, I can't
find any and I am not sure if this is possilbe. My code sample below and any
and all help is appreciated.

//This part works just fine
private void Save_Click(object sender, System.EventArgs e)

{

try

{

ResourceWriter rw = new ResourceWriter(@"C:\HOST_BACHEND.resources");

//

rw.AddResource("LOGO", this.pBox_Logo.Image);

rw.AddResource("HEADER_1", "HEADER TEST");

//

rw.Generate();

rw.Close();

}

catch(Exception myException)

{

MessageBox.Show(myException.Message);

}

}

----------------------------------------

//Extraction is the problem for just the image

try

{

IResourceReader reader = new ResourceReader(@"C:\HOST_BACHEND.resources");

IDictionaryEnumerator en = reader.GetEnumerator();

//

while (en.MoveNext())

{

MessageBox.Show(en.Key.ToString() +"\n" + en.Value.ToString()

+"\n" + en.Current.ToString() +"\n" + en.Entry.ToString());



if(en.Key.ToString() == "LOGO")

{

??????

}

if(en.Key.ToString() == "HEADER_1")

{

MessageBox.Show(en.Value.ToString());

}

}

}

catch(Exception myException)

{

MessageBox.Show(myException.Message);

}


Thanks

MikeY
 
P

Peter Duniho

if(en.Key.ToString() == "LOGO")

{

??????

}

if (en.Key.ToString() == "LOGO")
{
string strType;
byte[] rgbData;
MemoryStream stream;

((ResourceReader)reader).GetResourceData(en.Key.ToString(), out
strType, out rgbData);
stream = new MemoryStream(rgbData);
image = Image.FromStream(stream);
}

Or something like that? I admit, I haven't played with the ResourceReader
class much. It's possible you can get the Image instance directly from
the Value property, but off the top of my head I don't know how. The
above should work though. If you want to use the Value property directly,
the first thing I'd do if I were you is to break in the debugger when you
know the resource entry is the one you're interested in and see what the
type of the Value property actually is. That should give you some idea as
to how you're supposed to treat it.

I'll also suggest that rather than getting the enumerator directly, it
might make more sense to just do:

foreach (DictionaryEntry en in reader)
{
...
}

Pete
 
M

MikeY

Thanks Peter For your response.

Struggling with it, but trying it out.
Txs again.


if(en.Key.ToString() == "LOGO")

{

??????

}

if (en.Key.ToString() == "LOGO")
{
string strType;
byte[] rgbData;
MemoryStream stream;

((ResourceReader)reader).GetResourceData(en.Key.ToString(), out
strType, out rgbData);
stream = new MemoryStream(rgbData);
image = Image.FromStream(stream);
}

Or something like that? I admit, I haven't played with the ResourceReader
class much. It's possible you can get the Image instance directly from
the Value property, but off the top of my head I don't know how. The
above should work though. If you want to use the Value property directly,
the first thing I'd do if I were you is to break in the debugger when you
know the resource entry is the one you're interested in and see what the
type of the Value property actually is. That should give you some idea as
to how you're supposed to treat it.

I'll also suggest that rather than getting the enumerator directly, it
might make more sense to just do:

foreach (DictionaryEntry en in reader)
{
...
}

Pete
 
M

MikeY

Heres the answer for those who are looking for something similar for a
unembedded resource file.

IResourceReader reader = new ResourceReader(@"C:\HOST_BACHEND.resources");

//

foreach (DictionaryEntry de in reader)

{

if(de.Key.ToString() == "LOGO")

{

this.pBox_Logo.Image = (System.Drawing.Image)de.Value;

}


Hope it helps


MikeY said:
Thanks Peter For your response.

Struggling with it, but trying it out.
Txs again.


if(en.Key.ToString() == "LOGO")

{

??????

}

if (en.Key.ToString() == "LOGO")
{
string strType;
byte[] rgbData;
MemoryStream stream;

((ResourceReader)reader).GetResourceData(en.Key.ToString(), out
strType, out rgbData);
stream = new MemoryStream(rgbData);
image = Image.FromStream(stream);
}

Or something like that? I admit, I haven't played with the ResourceReader
class much. It's possible you can get the Image instance directly from
the Value property, but off the top of my head I don't know how. The
above should work though. If you want to use the Value property directly,
the first thing I'd do if I were you is to break in the debugger when you
know the resource entry is the one you're interested in and see what the
type of the Value property actually is. That should give you some idea as
to how you're supposed to treat it.

I'll also suggest that rather than getting the enumerator directly, it
might make more sense to just do:

foreach (DictionaryEntry en in reader)
{
...
}

Pete
 
Top