Hi!!!
I have a pda application that uses a dll that I made.
That dll has some images that i load as an embedded resource, when i run the application, it takes some time t load all images and i can see in the emulator the images loading... What can I do to make the images load at the same time
Thanks in advance

Loading images as embedded resource: How to optimize
Latika
this.pictureBox0.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox10.Image")));
actually be this:
this.pictureBox0.Image = ((System.Drawing.Image)(resources.GetObject("Images.Image0.gif")));
Alternatively, you can try this:
this.pictureBox0.Image = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("Images.Image0.gif");
Incidently, how are you adding the images to the assembly's resources: are you adding them to the project and setting their build action to embedded resource or are you adding them to a resource file
Zangow
Maybe i wasn’t clear ( bad english
I know that the statement I used works fine, I've already tryed it, but thanks for the tip, the problems is that in some pdas it gives an exception, so I dont want to use it....
So, I tryed the second choice, that works great.... in a windows application
In answer to yor question I'm using VS .NET 2003.
Thanks!
Monica
Joao Ferreirinha
I already tryed the code you putted in your last reply, and it worked great, but as I said, a coleague of mine used this "this.GetType().Assembly.GetManifestResourceStream(...) " and in some pdas it gives an exception (don't know why), so I wanted to use another aproach, but I can't seem to get it right... Well, i'm not quite shure how to solve this problem, but thanks a lot for your help
Monica
The Omnipotent
Sorry if you where expecting a reply sooner, but we had holliday here in Portugal (25-04)...
I don't know what models of PDAs it gives an exception, because it was a co-worker that catched that exception...
The exception is thrown consistently, but I arranjed a workaround
I use a try catch statement (in this I use GetResourceManifestStream(...) to get the pictures and if it gives an exception I use buttons instead of pictureboxes... It's a way to make it work always
Thanks a lot for your help, Neil
虫豸
Please also note that the "this.GetType().Assembly.GetResourceManifestStream(...) line of code in my example is different from your example in that I reference the resource using the fully qualified resource name which includes the assembly's namespace. You must do this or you will get an exception.
Cerberuss
"Images.0d.gif") );"
So, i wanto to try some other thing to workaround this problem, although it runs perfectly fine almost of the cases...
I'll give yuo a sample of my code:
I have a class libary ( that is a windows application ) that as a class: The images are located in the folder named Images:
using System;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
namespace Keyboard
{
public class PanelKeyboard : Panel
{
private System.Windows.Forms.PictureBox pictureBox0;
public PanelKeyboard( NumericInput numericInput, Image img )
{
//
// TODO: Add constructor logic here
//
_NumericInput = numericInput;
//InitializeComponent();
AddControls(img);
this.Visible = false;
this.Location = new System.Drawing.Point( numericInput.Location.X + 10, numericInput.Location.Y + numericInput.Height);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
private void AddPicturesToParent()
{
this.pictureBox0.Parent = this;
}
private void AddControls(Image img)
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PanelKeyboard));
this.pictureBox0 = new System.Windows.Forms.PictureBox();
AddPicturesToParent();
//this is the line where i get the exception
this.pictureBox0.Image = ((System.Drawing.Image)(resources.GetObject("Images.Image0.gif")));
this.pictureBox0.Location = new Point ( 0, 96 );
this.pictureBox0.Size = new System.Drawing.Size(64, 32);
this.pictureBox0.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox0_MouseUp);
this.pictureBox0.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox0_MouseDown);
}
The I have a SmartDeviceApplication that calls imports Keyboard.dll and instatiates it
I'm sorry if i am wasting your time, thank you very much Neil
Monica
Shreyas Patel
this.pictureBox0.Image = ((System.Drawing.Image)(resources.GetObject("Images.Image0.gif")));
I get the same exception
The second line of code "this.pictureBox0.Image = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("Images.Image0.gif");"
is what I have and it does work, but not in all pdas, and I want something that doesn't give me an exception...
I've been working on this for days, and I've got nothing, don’t know what to do..
I'm starting to think it's because of dlls (mscorlib) but I don't know what to do !!!!
I'm adding the images to the project and setting buid action as embedded resource...
Thanks for taking the time...
Monica
SQL2K5
Are you referencing the image resource correctly "Images.Image0.gif" implies that the assembly's full namespace is "Images" -- is this correct
I need to see more code to help you through this.
jpkuzma
this.pictureBox0.Image = ((System.Drawing.Image)(resources.GetObject("Images.Image0.gif")));
to this:
this.pictureBox0.Image = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("Keyboard.Images.Image0.gif"));
That should do it. The reason is that you must specify the assembly namespace when referencing an embedded resource. If you where to disassemble the compiled assembly and take a look at the generated IL, you would see this in the assembly's metadata:
.mresource public Keyboard.Images.Image0.gif
{
// Offset: 0x00000000 Length: 0x000004F6
}
yflie
I've already tryed it on a pda and it works fine, i have no problem loading the images, the Emulator is not as fast (didn't know that, my first project)...
I was wondering if thre is another way to laod the images:
This is the one I use :
I have a panel that contains the images (embedded resource) and this is how get them to show in the panel:
this.pictureBox0d.Image = new Bitmap( assembly.GetManifestResourceStream(this.GetType(),
"Images.0d.gif") );
The problem is that this doesn't work in all pdas
so I've tryed this way :
this.pictureBox0.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox10.Image")));
But this gives an exception :
An unhandled exception of type 'System.TypeLoadException' occurred in mscorlib.dll
Additional information: System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
The project is a Class Library. If I use the statement in a windows application it works fine.
Whats the problem here
Thanks in advance
Monica
dtb5571
string[] resourceNames = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
Peter
Mehyar Yahfoufi
Your answer is really VERY helpfull!!!
Jim Foster 2007
this.pictureBox0d.Image = new Bitmap(asm.GetManifestResourceStream(this.GetType(), "Images.0d.gif"));
try this:
Assembly asm = Assembly.GetExecutingAssembly();
this.pictureBox0d.Image = new Bitmap(asm.GetManifestResourceStream("Images.0d.gif"));
Also, are you using Visual Studio .NET 2003 or Visual Studio 2005 The emulators that came with VS .NET 2003 are notoriously slow, even on a fast PC. The VS 2004 emulators are MUCH better
Nicklas Gummesson