G
Guest
I'm trying to create a program that plots randomly colored pixels on a bitmap
& then displays the bitmap. When I run the program, I see the pixels being
plotted down the left side of the form. When it gets to the bottom, the
"Argument out of range exception" occurs. So, obviously the program starts.
The Help tells me that the argument isn't within the range of values, but it
doesn't explain how to fix the problem. So the Help doesn't help! It doesn't
tell me what the range of values are. What are the range of values? The
problem is with the "Y" parameter. The debugger tells me that the value
cannot be negative & must be less than Height.
Here follows the source code:
Private Sub PointillismToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
PointillismToolStripMenuItem.Click
Dim objGraphics As Graphics
Dim objRandom As System.Random
Dim RedColor As Integer
Dim GreenColor As Integer
Dim BlueColor As Integer
Dim Transparency As Integer
' Create a Graphics object using the memory bitmap.
objGraphics = Graphics.FromImage(objDrawingSurface)
' Initialize the Random object.
objRandom = New Random(Now.Millisecond)
Transparency = objRandom.Next(0, 256)
Dim Xcount As Integer
Dim Ycount As Integer
For Xcount = 1 To 1280
For Ycount = 1 To 964
RedColor = objRandom.Next(0, 256)
GreenColor = objRandom.Next(0, 256)
BlueColor = objRandom.Next(0, 256)
objDrawingSurface.SetPixel(Xcount, Ycount, Color.FromArgb(RedColor,
GreenColor, BlueColor))
' Draw myBitmap to the screen.
Me.CreateGraphics.DrawImage(objDrawingSurface, 0, 0)
Next Ycount
Next Xcount
End Sub
The problem occurs within the "For Ycount" loop at the "objDrawingSurface...".
So, how do I fix the problem. I'm about ready to give up.
Thank you. David
& then displays the bitmap. When I run the program, I see the pixels being
plotted down the left side of the form. When it gets to the bottom, the
"Argument out of range exception" occurs. So, obviously the program starts.
The Help tells me that the argument isn't within the range of values, but it
doesn't explain how to fix the problem. So the Help doesn't help! It doesn't
tell me what the range of values are. What are the range of values? The
problem is with the "Y" parameter. The debugger tells me that the value
cannot be negative & must be less than Height.
Here follows the source code:
Private Sub PointillismToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
PointillismToolStripMenuItem.Click
Dim objGraphics As Graphics
Dim objRandom As System.Random
Dim RedColor As Integer
Dim GreenColor As Integer
Dim BlueColor As Integer
Dim Transparency As Integer
' Create a Graphics object using the memory bitmap.
objGraphics = Graphics.FromImage(objDrawingSurface)
' Initialize the Random object.
objRandom = New Random(Now.Millisecond)
Transparency = objRandom.Next(0, 256)
Dim Xcount As Integer
Dim Ycount As Integer
For Xcount = 1 To 1280
For Ycount = 1 To 964
RedColor = objRandom.Next(0, 256)
GreenColor = objRandom.Next(0, 256)
BlueColor = objRandom.Next(0, 256)
objDrawingSurface.SetPixel(Xcount, Ycount, Color.FromArgb(RedColor,
GreenColor, BlueColor))
' Draw myBitmap to the screen.
Me.CreateGraphics.DrawImage(objDrawingSurface, 0, 0)
Next Ycount
Next Xcount
End Sub
The problem occurs within the "For Ycount" loop at the "objDrawingSurface...".
So, how do I fix the problem. I'm about ready to give up.
Thank you. David