Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 13th, 2008, 4:13 PM   #1
csrocker101
Programmer
 
Join Date: Dec 2006
Posts: 47
Rep Power: 0 csrocker101 is on a distinguished road
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??
csrocker101 is offline   Reply With Quote
Old Mar 13th, 2008, 4:40 PM   #2
Arla
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 164
Rep Power: 4 Arla is on a distinguished road
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).
Arla is offline   Reply With Quote
Old Mar 13th, 2008, 9:59 PM   #3
csrocker101
Programmer
 
Join Date: Dec 2006
Posts: 47
Rep Power: 0 csrocker101 is on a distinguished road
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
csrocker101 is offline   Reply With Quote
Old Mar 13th, 2008, 10:45 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Old Mar 14th, 2008, 12:29 AM   #5
BstrucT
Hobbyist Programmer
 
BstrucT's Avatar
 
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 175
Rep Power: 1 BstrucT is on a distinguished road
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.
BstrucT is offline   Reply With Quote
Old Mar 14th, 2008, 9:30 AM   #6
csrocker101
Programmer
 
Join Date: Dec 2006
Posts: 47
Rep Power: 0 csrocker101 is on a distinguished road
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.
csrocker101 is offline   Reply With Quote
Old Mar 14th, 2008, 10:41 AM   #7
mbd
Programmer
 
Join Date: Nov 2007
Posts: 86
Rep Power: 1 mbd is on a distinguished road
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.
mbd is offline   Reply With Quote
Old Mar 16th, 2008, 4:00 PM   #8
csrocker101
Programmer
 
Join Date: Dec 2006
Posts: 47
Rep Power: 0 csrocker101 is on a distinguished road
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!
csrocker101 is offline   Reply With Quote
Old Mar 17th, 2008, 12:57 AM   #9
BstrucT
Hobbyist Programmer
 
BstrucT's Avatar
 
Join Date: Dec 2007
Location: Durban, South-Africa
Posts: 175
Rep Power: 1 BstrucT is on a distinguished road
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.
BstrucT is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC