how to use GDI+ to color pixels from array

  • Thread starter Thread starter djharrison
  • Start date Start date
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
 
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
 
* (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.
 
Back
Top