G
Guest
I think I'm going insane, but thought I'd check with you all first before I
get myself commited!
Here's a method I've built to retrieve an image:
public static Image GetImage(string imageBaseName, ref int imageNum)
{
string fullName = "";
Bitmap image = null;
Stream stream;
Assembly assembly = Assembly.GetCallingAssembly();
// Is this just a single (ie. one-time) image?
if (imageNum == -1)
{
fullName = imageBaseName + ".jpg";
stream = assembly.GetManifestResourceStream(fullName);
}
else // Or is it one of many in an animation
{
fullName = imageBaseName + imageNum.ToString() + ".jpg";
stream = assembly.GetManifestResourceStream(fullName);
if (stream == null)
{
imageNum = 1; // Reset sequence
fullName = imageBaseName + "1.jpg";
stream = assembly.GetManifestResourceStream(fullName);
}
}
if (stream != null)
image = new Bitmap(stream);
stream.Close();
return image;
}
The idea behind this method is that it can be used to retrieve an image for
a one time usage or use it to retrieve one frame within an animation. What's
driving me crazy is this:
If I use it in its simplest form then it works fine. Here's an example:
GetImage("Multimedia.Anim1", -1); // This works perfectly
But if I try to retrieve the same embedded image in animation mode then it
fails:
GetImage("Multimedia.Anim", 1); // This does not work
In the second case, I triple-checked that "fullName" is correct and yet
"stream" ends up being a nul value. HOW ON EARTH CAN THAT BE?!?!?
get myself commited!
Here's a method I've built to retrieve an image:
public static Image GetImage(string imageBaseName, ref int imageNum)
{
string fullName = "";
Bitmap image = null;
Stream stream;
Assembly assembly = Assembly.GetCallingAssembly();
// Is this just a single (ie. one-time) image?
if (imageNum == -1)
{
fullName = imageBaseName + ".jpg";
stream = assembly.GetManifestResourceStream(fullName);
}
else // Or is it one of many in an animation
{
fullName = imageBaseName + imageNum.ToString() + ".jpg";
stream = assembly.GetManifestResourceStream(fullName);
if (stream == null)
{
imageNum = 1; // Reset sequence
fullName = imageBaseName + "1.jpg";
stream = assembly.GetManifestResourceStream(fullName);
}
}
if (stream != null)
image = new Bitmap(stream);
stream.Close();
return image;
}
The idea behind this method is that it can be used to retrieve an image for
a one time usage or use it to retrieve one frame within an animation. What's
driving me crazy is this:
If I use it in its simplest form then it works fine. Here's an example:
GetImage("Multimedia.Anim1", -1); // This works perfectly
But if I try to retrieve the same embedded image in animation mode then it
fails:
GetImage("Multimedia.Anim", 1); // This does not work
In the second case, I triple-checked that "fullName" is correct and yet
"stream" ends up being a nul value. HOW ON EARTH CAN THAT BE?!?!?