![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Dec 2006
Posts: 47
Rep Power: 0
![]() |
Help loading images into Bitmap Array
I'm using the .NET compact Framework to make a phone and trying to load six images into a Bitmap Array. For some reason I keep getting errors at runtime. Here is my code:
public partial class Form1 : Form
{
Bitmap[] image = new Bitmap[5];
public Form1()
{
InitializeComponent();
image[0] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mobile Apps and Devices.Resources.Black.bmp"));
image[1] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mobile Apps and Devices.Resources.Blue.bmp"));
image[2] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mobile Apps and Devices.Resources.Grey.bmp"));
image[3] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mobile Apps and Devices.Resources.Red.bmp"));
image[4] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mobile Apps and Devices.Resources.White.bmp"));
image[5] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Mobile Apps and Devices.Resources.Yellow.bmp"));
}I Think it has something to do with where I am placing my files. But I added them the correct way by right-clicking my project in the solution explorer->Open->Resources->Add Resources->Add existing item but...it's still not working! It compiles but at run time I get exceptions saying "NullReferenceException." I have put the images files EVERYWHERE. I put them in the debug file as well and it's still not working!! Any Ideas on what I am doing wrong?? |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 164
Rep Power: 4
![]() |
Re: Help loading images into Bitmap Array
I'd guess it's as easy as your statement
Bitmap[] image = new Bitmap[5]; You're only allowing for 5 things, yet you're adding 6, therefore the last one is going to bomb out (think that's it from a very quick review). |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Dec 2006
Posts: 47
Rep Power: 0
![]() |
Re: Help loading images into Bitmap Array
I don't think that has anything to do with it since 0 is counts as an index in the array..as in 0, 1, 2, 3 4, 5...Plus I think if that was the problem it would give me an array out of bounds exception
|
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Re: Help loading images into Bitmap Array
new Bitmap[5] creates an array of 5 bitmaps, indices 0 through 4.
You are correct that you would get a bounds exception. And you will, when you fix the first one. The exception is happening somewhere before the image[5] = line.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 175
Rep Power: 1
![]() |
Re: Help loading images into Bitmap Array
Just a thought, I am probably wrong, but had a similar problem.
Are all the image files you are importing in the same format? Worth having a double look. >BstrucT<
__________________
The more the human race tries to change everything, when not needed, the less will they be able to change themselves when they need to. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Dec 2006
Posts: 47
Rep Power: 0
![]() |
Re: Help loading images into Bitmap Array
Ya all the images are in ".bmp" format. I am using the .NET compact framework and apparently I read somewhere that mobile devices (including the emulator) cannot read files from a computers Hard drive directory. I tried referencing it directly from my hard drive by using:
image[0] = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("C:\\Documents and Settings\\Kevin Brunette\\Desktop.Mobile Apps and Devices (200600255)\\Mobile Apps and Devices (200600255)\\Resources\\Black.bmp"))And this time I get a "DirectoryNotFoundException" but how cant that be when the file is there! I have put it everywhere in the debug folder, added a folder in the solution explorer called "resources" and tried to reference from that and STILL getting the same exceptions. |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Nov 2007
Posts: 86
Rep Power: 1
![]() |
Re: Help loading images into Bitmap Array
my advice would be to step through your progam in the debugger and add all those function calls as watches. i might separate the
"...new Bitmap(Assembly..." part into two lines so it would be easier to inspect the return value of getmanifestresourcestream. |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Dec 2006
Posts: 47
Rep Power: 0
![]() |
Re: Help loading images into Bitmap Array
I FINALLY FIXED the problem. The .NET framework apparently can't recognize drive spaces and files on a normal computer so you have to make the resources embedded. By doing the following...
[code]class ImageFiles { image[0] = Properties.Resources.Red; } It fixed the problem and now works perfectly! |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 175
Rep Power: 1
![]() |
Re: Help loading images into Bitmap Array
Cool man, will make a make a note of that for myself in my C# file for future reference.
hehe, glad you got it sorted.
__________________
The more the human race tries to change everything, when not needed, the less will they be able to change themselves when they need to. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| dynamic array help | quickster12 | C++ | 4 | Nov 29th, 2007 11:52 PM |
| problem processing file into a char array | csrocker101 | C++ | 1 | May 8th, 2007 11:50 PM |
| changing size of an array | Eric the Red | Java | 3 | Apr 3rd, 2006 8:19 PM |
| saving and loading an array of object in acii file | lamefif | C++ | 2 | Jan 5th, 2006 3:08 PM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 2:36 AM |