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 PointillismTool StripMenuItem_C lick(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
PointillismTool StripMenuItem.C lick
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.FromIm age(objDrawingS urface)
' Initialize the Random object.
objRandom = New Random(Now.Mill isecond)
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)
objDrawingSurfa ce.SetPixel(Xco unt, Ycount, Color.FromArgb( RedColor,
GreenColor, BlueColor))
' Draw myBitmap to the screen.
Me.CreateGraphi cs.DrawImage(ob jDrawingSurface , 0, 0)
Next Ycount
Next Xcount
End Sub
The problem occurs within the "For Ycount" loop at the "objDrawingSurf ace...".
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 PointillismTool StripMenuItem_C lick(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
PointillismTool StripMenuItem.C lick
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.FromIm age(objDrawingS urface)
' Initialize the Random object.
objRandom = New Random(Now.Mill isecond)
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)
objDrawingSurfa ce.SetPixel(Xco unt, Ycount, Color.FromArgb( RedColor,
GreenColor, BlueColor))
' Draw myBitmap to the screen.
Me.CreateGraphi cs.DrawImage(ob jDrawingSurface , 0, 0)
Next Ycount
Next Xcount
End Sub
The problem occurs within the "For Ycount" loop at the "objDrawingSurf ace...".
So, how do I fix the problem. I'm about ready to give up.
Thank you. David
Comment