Forgive my lack of knowledge, as I am just starting out with Visual Basic.
I am attempting to draw lines on a picturebox and will be using a trackbar to scale it.
What I have in code below will draw what I need, but seems to not be saving the original (unscaled) image to a bitmap. I need the trackbar, at every point, to grab the original image and scale it at the trackbar.value. I need to do it this way so it wont distort/blur the image because of scaling the same image too many times.
A background image is default, so removing that image upon drawing of lines.
This is the code to draw the lines using points)
Imports System.Drawing.Drawing2D
Imports System.Math
Imports System.Drawing.Graphics
Public Module DrawVaCrossframe
Public Bmp As New Bitmap(609, 330)
Public g As Graphics = FromImage(Bmp)
Public Property rotateAngle As Double
Public Sub drawVACF()
CrossframesMain.pbVACFDraw.BackgroundImage = Nothing
CrossframesMain.pbVACFDraw.BackColor = Color.Black
CrossframesMain.pbVACFDraw.Refresh()
g = CrossframesMain.pbVACFDraw.CreateGraphics
Dim pntWP1 As New Point
If dblGdrDrop >= 0.0 Then
pntWP1 = New Point(CInt((sngPnlWidth) - (dblBayHalfWidth)), CInt((sngPnlHeight) - (dblWebHalfDepth)))
Else
pntWP1 = New Point(CInt((sngPnlWidth) - (dblBayHalfWidth)), CInt(CInt(sngPnlHeight) - (dblWebHalfDepth) - dblGdrDrop))
End If
Dim pntWp2 As New Point(pntWP1.X, pntWP1.Y + CInt(dblWebDepth))
Dim pntWp3 As New Point(pntWP1.X + CInt(dblBayWidth), pntWP1.Y + CInt(dblGdrDrop))
Dim pntWP4 As New Point(pntWp3.X, pntWp3.Y + CInt(dblWebDepth))
g.DrawLine(whitePen, pntWP1, pntWp2)
g.DrawLine(whitePen, pntWp3, pntWP4)
That code gets my image, but is very small, so I need to scale it. When I try to send it to a Bitmap,
CrossframesMain.pbVACFDraw.Image = Bmp
after `g.drawline`, the image comes on screen and then immediately off.
I am calling drawVACF() from the mainform with a button and then changing the trackbar on the same mainform.
Imports System.Drawing.Drawing2D
Public Class CrossframesMain
Public g As Graphics
Private Bmp As New Bitmap(1218, 660)
Public Sub New()
InitializeComponent()
tbarVACF.Minimum = 1
tbarVACF.Maximum = 9
tbarVACF.SmallChange = 1
tbarVACF.LargeChange = 2
tbarVACF.Value = 1
tbarVACF.TickFrequency = 2
tbarVACF.TickStyle = TickStyle.Both
End Sub
Private Sub tbarVACF_ValueChanged(sender As Object, e As EventArgs) Handles tbarVACF.ValueChanged
Dim width As Integer
Dim height As Integer
Dim originalImage As Bitmap = CType(pbVACFDraw.Image, Bitmap)
Dim g As Graphics = Graphics.FromImage(originalImage)
Try
If originalImage Is Nothing Then
Return
Else
If Bmp Is Nothing Then
Return
Else
lblTbarZoom.Text = "Zoom Level: " & tbarVACF.Value
If tbarVACF.Value > 0 Then
width = CInt(Bmp.Width * (0.25 * tbarVACF.Value))
height = CInt(Bmp.Height * (0.25 * tbarVACF.Value))
End If
End If
Dim _bmpImage = Bmp
Dim scaledBitmap As New Bitmap(_bmpImage, width, height)
Dim scaledBmp As Graphics = Graphics.FromImage(scaledBitmap)
scaledBGBmp.InterpolationMode = InterpolationMode.HighQualityBicubic
pbVACFDraw.Image = scaledBitmap
g.DrawImage(scaledBitmap, width, height)
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
I would greatly appreciate any and all help and direction with this.
What I have tried:
Hard to say what all I have tried, because it has all run together over the last two weeks attempting to learn what I need to do. I am at my wits end.