how to use GDI+ to color pixels from array

D

djharrison

Greetings,

I am attempting to develop an application that will color the pixels
in a PictureBox based on the x and y coordinates for individual pixels
in an array. I would like to load the values into the array from a
database. Does this sound feasible? I'm new to CDI+ programming. I
thougnt he SetPixel method would work best but i'm not sure how to
proceed. Can I grab the values right from the database into the
PictureBox?

Any help is appreciated.

Daryl
 
J

Jeremy Todd

I am attempting to develop an application that will color the pixels
in a PictureBox based on the x and y coordinates for individual pixels
in an array. I would like to load the values into the array from a
database. Does this sound feasible? I'm new to CDI+ programming. I
thougnt he SetPixel method would work best but i'm not sure how to
proceed. Can I grab the values right from the database into the
PictureBox?

The best way to do that would be to load the values from the database
into a new Bitmap object, then assign that Bitmap to the PictureBox's Image
property:

Dim bmp As Bitmap = New Bitmap(100, 100)

For x As Integer = 0 to xxx
For y As Integer = 0 to yyy
Dim currentColor As Color
currentColor = GetColorFromDatabase(x, y)
bmp.SetPixel(x, y, currentColor)
Next y
Next x

PictureBox1.Image = bmp

But really, why not just store the bitmap files themselves in the
database (or even just as files)? That would greatly speed things up, not
to mention saving tons of space in the database and drastically simplifying
queries.

Jeremy
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (djharrison) scripsit:
I am attempting to develop an application that will color the pixels
in a PictureBox based on the x and y coordinates for individual pixels
in an array. I would like to load the values into the array from a
database. Does this sound feasible? I'm new to CDI+ programming. I
thougnt he SetPixel method would work best but i'm not sure how to
proceed. Can I grab the values right from the database into the
PictureBox?

Write the byte array containing the whole bitmap file into a
'MemoryStream', then create a new 'Bitmap' object from the data (see
overloaded versions of the 'Bitmap' constructur). Then you can use the
bitmap's 'GetPixel' and 'SetPixel' methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top