Reputation: 3003
I want to store images in a .dll file and use them for my winform application. but Im not able to load .dll content
System.IO.Stream stream;
System.Reflection.Assembly assembly;
Image bitmap;
assembly = System.Reflection.Assembly.LoadFrom(Application.ExecutablePath);
stream = assembly.GetManifestResourceStream("global::template.Properties.Resources.test.png");
bitmap = Image.FromStream(stream);
this.background.titleImage = bitmap; // image box
Upvotes: 1
Views: 2214
Reputation: 38434
The most likely problem is that the path you are specifying in GetManifestResourceStream() is not correct.
I find the following helpful to debug these issues:
e.g. "PrismDemo.Properties.Resources.resources.app.ico"
Upvotes: 3
Reputation: 941218
You are using the wrong name, "global::" doesn't appear in the manifest resource name. A typical name would be project.test.png if you added the resource to the project and set its Build Action to "Embedded Resource". To avoid guessing at the name, use Ildasm.exe and find the .mresource in the manifest.
However, your name suggests you added the resource in the Project + Properties, Resources tab. Good idea, that auto-generates a property name for the resource. You'd use project.Properties.Resources.test to reference it. You'll get an Image back, no need to use GetManifestResourceStream.
The project name I listed above is the default namespace name you assigned to the project. Project + Properties, Application tab, Default namespace setting.
Upvotes: 2