gif as embedded resource

A

Alain R.

Hi,

I have some problem to retrieve an image from my application.
Here is my code :

Stream imgStream = null;
Assembly a = Assembly.GetExecutingAssembly();
imgStream = a.GetManifestResourceStream("SW_Audit.img_ok.gif");

PBStep1.Image = new Bitmap(imgStream);

before i embedded this image by doing :
Project-> property-> resources -> add resource-> add existing resource
-> "img_ok.gif"

My application namespace is "SW_Audit".

so what have i done wrong ?

thanks a lot,

Al.
 
J

Jon Skeet [C# MVP]

I have some problem to retrieve an image from my application.
Here is my code :

Stream imgStream = null;
Assembly a = Assembly.GetExecutingAssembly();
imgStream = a.GetManifestResourceStream("SW_Audit.img_ok.gif");

PBStep1.Image = new Bitmap(imgStream);

before i embedded this image by doing :
Project-> property-> resources -> add resource-> add existing resource
-> "img_ok.gif"

My application namespace is "SW_Audit".

so what have i done wrong ?

Hard to say:

1) What exactly is happening?
2) Is imgStream null?
3) Have you used ildasm/reflector/anything else to see what manifest
resources are actually present?

Jon
 
A

Alain R.

Yes imgStrem is still equal to NULL :-(
Hard to say:

1) What exactly is happening?
2) Is imgStream null?
3) Have you used ildasm/reflector/anything else to see what manifest
resources are actually present?

Jon
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

A time ago I posted some code for exactly this, take a look at the archives.

From your code I think that the problem is cause the resourse name shoudl
have the namespace in front. So if the image is named Image1.gif the name fo
the resource is mynamespace.image1.gif
 
J

Jon Skeet [C# MVP]

A time ago I posted some code for exactly this, take a look at the archives.

From your code I think that the problem is cause the resourse name shoudl
have the namespace in front. So if the image is named Image1.gif the name fo
the resource is mynamespace.image1.gif

It looks like he's already got the namespace there though: SW_Audit.

I think it's easiest just to see what's actually there...

Jon
 
N

Nicholas Paldino [.NET/C# MVP]

It might be that most of the code in the assembly places types in the
assembly SW_Audit, but I'm guessing that isn't the default namespace for the
project. The OP has to go to the settings of his project, and make sure
that SW_Audit is listed in the "Default namespace" textbox on the
"application" page for the project properties.
 
A

Alain R.

So for your information, SW_Audit is the real default namespace of my
project (application tab of project-> property).

So where is the problem ?

A.
 
N

Nicholas Paldino [.NET/C# MVP]

Alain,

I just realized that you are adding a resource through a resource file,
not embedding a resource. If you were embedding a resource, then the code
you are using would work. However, you have to ad "img_ok.gif" as an item
to your project, and change the build action to "Embedded Resource".

When you go to the project and add a resource, it will create a
resources file that is added to your project. If you are in Visual Studio
2005, you should also see a new .cs file which contains strongly typed
wrappers for the items in your resource file.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Alain R. said:
So for your information, SW_Audit is the real default namespace of my
project (application tab of project-> property).

So where is the problem ?


Get a list of all the resources you have using GetManifestResourceNames
 
A

Alain R.

In fact, i deleted my former picture from added files, clean the
project, add it again, remove all possible other resources from
Project->property.

Rebuild everything, and the code which was not working till now, works
perfectly now :-(((

so i must have done something wrong before and let the VC# in not
stable/standard way.

Al.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top