Using VB.NET... Following an example from from Francesco Balena's 'Programming Microsoft Visual Basic.NET'... Can draw an image on the form, but need to put it inside a picturebox (because, when the user drags the image, it needs to move around the form.)
Here's the code to draw to the form from a numericupdown control, just for the X dimension...(PictureBox2 already contains the image to be skew'ed)
---BEGIN---
Private Sub NumericUpDown4_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NumericUpDown4.ValueChanged
Dim gr As Graphics = Me.CreateGraphics
Dim bmp As New Bitmap(PictureBox2.Image)
gr.Clear(Color.White)
DrawSkewImage(gr, bmp, 0, 0, NumericUpDown4.Value, 0)
bmp.Dispose()
gr.Dispose()
End Sub
Sub DrawSkewImage(ByVal gr As Graphics, ByVal bmp As Bitmap, ByVal x As
Single, ByVal y As Single, ByVal dx As Single, ByVal dy As Single)
' Find the position of (x1,y1) and (x2,y2).
Dim x1 As Single = x + bmp.Width
Dim y1 As Single = y + dy
Dim x2 As Single = x + dx
Dim y2 As Single = y + bmp.Height
' Create the points array.
Dim points() As Point = {New Point(x, y), New Point(x1, y1), New
Point(x2, y2)}
' Draw the skewed image
gr.DrawImage(bmp, points)
End Sub
---END---
The above code will read the picturebox.image into the bitmap. The Points Array is created, and the graphic draws the image, with the points array onto the background of the application.
My goal: redirect the drawing into the picturebox, replacing the content of the picturebox with the newly drawn graphic...
Any recommendations?
- e
Here's the code to draw to the form from a numericupdown control, just for the X dimension...(PictureBox2 already contains the image to be skew'ed)
---BEGIN---
Private Sub NumericUpDown4_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles NumericUpDown4.ValueChanged
Dim gr As Graphics = Me.CreateGraphics
Dim bmp As New Bitmap(PictureBox2.Image)
gr.Clear(Color.White)
DrawSkewImage(gr, bmp, 0, 0, NumericUpDown4.Value, 0)
bmp.Dispose()
gr.Dispose()
End Sub
Sub DrawSkewImage(ByVal gr As Graphics, ByVal bmp As Bitmap, ByVal x As
Single, ByVal y As Single, ByVal dx As Single, ByVal dy As Single)
' Find the position of (x1,y1) and (x2,y2).
Dim x1 As Single = x + bmp.Width
Dim y1 As Single = y + dy
Dim x2 As Single = x + dx
Dim y2 As Single = y + bmp.Height
' Create the points array.
Dim points() As Point = {New Point(x, y), New Point(x1, y1), New
Point(x2, y2)}
' Draw the skewed image
gr.DrawImage(bmp, points)
End Sub
---END---
The above code will read the picturebox.image into the bitmap. The Points Array is created, and the graphic draws the image, with the points array onto the background of the application.
My goal: redirect the drawing into the picturebox, replacing the content of the picturebox with the newly drawn graphic...
Any recommendations?
- e