![]() |
|||
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?
CommentsHi,
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,
By: rekha singh | 03 May 2010
|
