Pixel Plotting 2

J

Jacky Luk

Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
Dim myBitmap As New Bitmap("lake.jpg")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
myBitmap.Height)
' Set each pixel in myBitmap to black.
Dim Xcount As Integer
For Xcount = 0 To myBitmap.Width - 1
Dim Ycount As Integer
For Ycount = 0 To myBitmap.Height - 1
myBitmap.SetPixel(Xcount, Ycount, Color.Black)
Next Ycount
Next Xcount
' Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
myBitmap.Height)

End Sub


Hi, e is empty... how to initialize the e object?
Thanks
Jack
 
C

Cor Ligthert

Jacky,

Something as this
\\\
Dim bm As New Bitmap(120, 20)
Dim g As Graphics = Graphics.FromImage(bm)
////

I hope this helps

Cor
 
C

Cor Ligthert

Jacky,

You cannot use e because it is already used in the parameters.

You can change that e for g in your parameters and than it would work in
your procedure with e.

However, because the fact that for everybody (not by rule however it is done
very conequently )the e is the eventargument, is that very confusing (even
for you after a while) and will I very much advice you not to do that.

I hope this gives the idea why?

Cor
 
H

Herfried K. Wagner [MVP]

Jacky Luk said:
Private Sub Form1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
Dim myBitmap As New Bitmap("lake.jpg")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
myBitmap.Height)
[...]
Hi, e is empty... how to initialize the e object?

Add the code to the form's 'Paint' event handler or to an overridden
'OnPaint' method instead of adding it to a 'Click' event handler.
 

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