Resources

D

DaveL

Hello
I use the Below code to Extract Images from the Executing Assemblys
Resource....

What i would like to know is
I have other images in another dll and this dll is referenced in the
application

How to Get to The Dlls Resources From the Executing Assembly

public static Bitmap GetImage(string ImageName,int Width,int Height)
{
Bitmap oBitMap = null;
Icon oIcon = null;
Stream BitStream = null;
Assembly assembly = Assembly.GetExecutingAssembly();
string IconName = string.Format("{0}.{1}",
assembly.GetName().Name, ImageName.ToUpper());


if (ImageName.IndexOf("ICO") > -1)
{
BitStream = assembly.GetManifestResourceStream(IconName);
oIcon = new Icon(BitStream, 32, 32);
oBitMap = oIcon.ToBitmap();
}
else
{
BitStream = assembly.GetManifestResourceStream(IconName);
oBitMap = new Bitmap(BitStream);
oBitMap = new Bitmap(oBitMap, Width, Height);
}
oIcon = null;
BitStream = null;
return oBitMap;
}
 
J

Jeff Johnson

What i would like to know is
I have other images in another dll and this dll is referenced in the
application

Is this the question? Because it's not a question.
How to Get to The Dlls Resources From the Executing Assembly

Is this the question? Because you mention the "executing assembly," and
above you talked about "another DLL," which suggests to me that it is NOT
the executing assembly. So what is it exactly you want?
 
D

DaveL

I want to extract image(s) from another dll
Its just a nother dll other than the .exe running

for instance code is running a form
i want to load the buttons with the pictures required
there located in a dll..

hope that helps

the code i show'd just gets the current exectuing assembly (which is not the
dll where the picturs are located in the resource)

daveL
 
J

Jeff Johnson

I want to extract image(s) from another dll
Its just a nother dll other than the .exe running

for instance code is running a form
i want to load the buttons with the pictures required
there located in a dll..

hope that helps

the code i show'd just gets the current exectuing assembly (which is not
the dll where the picturs are located in the resource)

I THINK I have done this before, so let me check some code. I could be
wrong, though; I might have gotten the resources from the executing
assembly. Give me a bit....
 
J

Jeff Johnson

I THINK I have done this before, so let me check some code. I could be
wrong, though; I might have gotten the resources from the executing
assembly. Give me a bit....

It's not much different from the code you had. Create a new form and then
paste this over the code (note that this code is only looking for icons):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace ResourceLoader
{
public partial class Form1 : Form
{
private string _currentResource;
private Assembly _targetAssembly;

public Form1()
{
InitializeComponent();
}

private void loadButton_Click(object sender, EventArgs e)
{
LoadResourceNames();
}

private void LoadResource()
{
Stream resourceStream =
_targetAssembly.GetManifestResourceStream(_currentResource);
Icon icn = new Icon(resourceStream);
resourcePictureBox.Image = icn.ToBitmap();
}

private void LoadResourceNames()
{
// Optionally you could put an OpenFileDialog on the form and pick any
file
_targetAssembly = Assembly.LoadFile(@"<path to your DLL>");

string[] names = _targetAssembly.GetManifestResourceNames();

resourceListBox.Items.Clear();
resourceListBox.Items.AddRange(names);
}

private void resourceListBox_SelectedIndexChanged(object sender, EventArgs
e)
{
if (resourceListBox.SelectedIndex != -1)
{
string selectedResource = (string)resourceListBox.SelectedItem;

if (selectedResource.EndsWith(".ico") &&
string.Compare(selectedResource, _currentResource) != 0)
{
_currentResource = selectedResource;
LoadResource();
}
}
}
}
}
 
J

Jeff Johnson

I guess there were a couple of controls on the form I forgot to mention....

Anyways, you should be able to figure out that you need a button wired to
this handler:
private void loadButton_Click(object sender, EventArgs e)

and a list box wired to this one:
private void resourceListBox_SelectedIndexChanged(object sender,
EventArgs e)

Or you could just examine the code and see what it's doing. It's not rocket
science....
 

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