DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Storing images in variables

By: rekha singh | 03 May 2010 5:20 pm

Hi,

I'm new to vb.net. I am trying to write a program that will create sudoku games. However I want to load the pictures that represent the numbers 1 to 9 in to an array before asigning them to the PictureBoxes on my form. I decided to do it this way as I think it wll be quicker as the numbers wil be changing rapidly and there will be fewer IOs. The picture files themselves are only just over 200 bytes each.

The array I am using is declared like this:
 
Dim picImages(2, 9) As PictureBox ' 0-black, 1-red, 2-blue
 
Then I am assigning the picture to it:
picImages(0, 1).Image = System.Drawing. Bitmap.FromFile( strPath &
"black1.png" )
picImages(0, 2).Image = System.Drawing. Bitmap.FromFile( strPath &
"black2.png" ) etc.
 
The idea is that I can then assign it to a picture box on the form like this:
PictureBox1. Image = picImages(intCol, intNum).Image
 
However it does not like assigning the images to the variables. It gives an error message saying "The reference object is not defined to an instance object." (The actual message in French reads "La référence d'objet n'est pas définie à  une instance d'un objet." Please forgive me if my translation is off.)
 
I know that putting:
picImage(0, 1) = Picturebox1
before the assignment, solves this problem (for the first assignment, anyway) but it also displays the image on the form, which is not what I want to do just yet.
 
I am sure I am doing something silly but I do not know what. Any ideas?
 

Comments

Hi,
 
I also found using resources in this way is quite faster than accessing file directly. Specially when you are developing any games. Naturally, file/disk access is costly than this. I don't think you are doing anything silly. By the way, the error you are talking about can be solved this way.
 
Dim picImages(2, 9) As New PictureBox
 

 

By: rekha singh | 03 May 2010

Hi, 

Thanks for the tip but I get the error message that arrays can not be declared with the New keyword.

However I have managed to get around my problem by declaring a variable picDummy as New PictureBox and assignig that to my array variable before loading the image.

Seems a long winded method but it works.

By: rekha singh | 03 May 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move