473,657 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How best to load an image resource?

I want to create a special DLL that will contain only images. My application
will then load these images when it needs them. So I searched MSDN and found
this article:
http://msdn.microsoft.com/library/de...sInProject.asp

I followed the example but could not get it to work. Specifically, here's
my code:

Assembly myAssembly = Assembly.GetExe cutingAssembly( );
Stream myStream =
myAssembly.GetM anifestResource Stream("DataObj ects.test1.jpg" );
Bitmap image = new Bitmap(myStream );

this.ClientSize = new Size(image.Widt h, image.Height);
pictureBox1.Ima ge = image;
Notes:
- My DLL is called "DataObject s" and so is the namespace therein
- I loaded a sample image "test1.jpg" into the DLL and recompiled it

But the code fails on the 2nd line: "Stream myStream"

What am I doing wrong?

--
Robert W.
Vancouver, BC
www.mwtech.com

Nov 17 '05 #1
2 8988
I believe this was discussed a day or two ago not exactly your problem but
something like it, maybe looking at this:

http://msdn.microsoft.com/newsgroups...sloc=en-us&p=1

will point you in the right direction.

Hope that helps
Mark.

"Robert W." wrote:
I want to create a special DLL that will contain only images. My application
will then load these images when it needs them. So I searched MSDN and found
this article:
http://msdn.microsoft.com/library/de...sInProject.asp

I followed the example but could not get it to work. Specifically, here's
my code:

Assembly myAssembly = Assembly.GetExe cutingAssembly( );
Stream myStream =
myAssembly.GetM anifestResource Stream("DataObj ects.test1.jpg" );
Bitmap image = new Bitmap(myStream );

this.ClientSize = new Size(image.Widt h, image.Height);
pictureBox1.Ima ge = image;
Notes:
- My DLL is called "DataObject s" and so is the namespace therein
- I loaded a sample image "test1.jpg" into the DLL and recompiled it

But the code fails on the 2nd line: "Stream myStream"

What am I doing wrong?

--
Robert W.
Vancouver, BC
www.mwtech.com

Nov 17 '05 #2
Hi Mark,

I clicked on that link in 2 different browsers but it's not bringing up any
specific topic. Could you give me the name of a title or some keywords to
find the thread you're referring to?

--
Robert W.
Vancouver, BC
www.mwtech.com

"Mark R. Dawson" wrote:
I believe this was discussed a day or two ago not exactly your problem but
something like it, maybe looking at this:

http://msdn.microsoft.com/newsgroups...sloc=en-us&p=1

will point you in the right direction.

Hope that helps
Mark.

"Robert W." wrote:
I want to create a special DLL that will contain only images. My application
will then load these images when it needs them. So I searched MSDN and found
this article:
http://msdn.microsoft.com/library/de...sInProject.asp

I followed the example but could not get it to work. Specifically, here's
my code:

Assembly myAssembly = Assembly.GetExe cutingAssembly( );
Stream myStream =
myAssembly.GetM anifestResource Stream("DataObj ects.test1.jpg" );
Bitmap image = new Bitmap(myStream );

this.ClientSize = new Size(image.Widt h, image.Height);
pictureBox1.Ima ge = image;
Notes:
- My DLL is called "DataObject s" and so is the namespace therein
- I loaded a sample image "test1.jpg" into the DLL and recompiled it

But the code fails on the 2nd line: "Stream myStream"

What am I doing wrong?

--
Robert W.
Vancouver, BC
www.mwtech.com

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
9241
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
4
48991
by: Ed Sutton | last post by:
I have been searching for how to get an icon resource and load it into an ImageList. I added an *.ico file to my project and set the files "Build Action" to "Embedded Resource". Is there any easy way to do this? This was easy to do in the old MFC. I can not find the answer in C#. I also need to embed an XML file into the resource and load it at run time. I am hoping once I figure out how to load an icon resource then loading an XML...
2
1732
by: Fernando Lopes | last post by:
Hey there! Someone knows how can I get and show an embbed resource image? I'm developing a web custom control and this control have some images and I want to put all these images like a embbed resource. Tks. Fernando Lopes
5
10208
by: Paul Cheetham | last post by:
Hi, I have some custom colour cursors which I have added to my c# project, and set them to be compiled as "Embedded Resource" It seems impossible to load a colour cursor using the standard Cursor class, so I have had to resort to loading it using the Win32 API, and creating the cursor with - new Cursor(HCURSOR) The code I am using is shown at the bottom of this post.
3
12116
by: UJ | last post by:
I've got an image I want to embed in a dll to use on a screen later. I've got it in a resource file, got it to compile in to the dll. The problem is getting it back out. It seems like my problem is in the get resource code. The code I'm using is: System.Reflection.Assembly myAssembly; myAssembly = this.GetType().Assembly;
0
1092
by: poojo hackma | last post by:
How can I load a System Resource image into a PictureBox with the CLR? Code: //----------------------------------------- System::Windows::Forms::PictureBox^ PictureBox1; System::IO::Stream^ resource; System::Void Button_Click(System::Object^ sender, System::EventArgs^ e) { resource = Assembly::GetManifestResourceStream("Fido.jpg");
8
12068
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files but I'd like to be able to load a file specified in a .resx resource. I've added my .xaml file to the .resx and can load it in using ResourceManager::GetObject(). The object returned is a System::Array^ which contains System::Byte objects. The...
2
6207
by: Yoavo | last post by:
Hi, In my application I need to load a bitmap which exists on an external DLL. How do I do it ? Yoav.
8
3020
by: john_woo | last post by:
Hi, I'm wondering whether it is possible that makes page load image only on demand. is there any idea? -- Thanks John
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.