dlaksmi
dlaksmi

Reputation: 369

How to custom resize Bitmap from picturebox before save it with VB.NET

The code that draws the signature is taken from here:
How to draw a signature and save it to disc as a Bitmap?

I'm trying to resize Bitmap before saving it.

Before the line of code below, I want to resize the Bitmap. Is it possible to apply? Or do I need to add a smaller PictureBox that is the size I want?

imgSignature.Save(signaturePath, ImageFormat.Png)

Please Guide me

Thanks

Public Class Form1
    Private signatureObject As New Dictionary(Of Integer, List(Of Point))
    Private signaturePen As New Pen(Color.Black, 4)
    Private currentCurve As Integer = -1
    Private Sub DrawSignature(g As Graphics)
        g.CompositingQuality = CompositingQuality.HighQuality
        g.SmoothingMode = SmoothingMode.AntiAlias

        For Each curve In signatureObject
            If curve.Value.Count < 2 Then Continue For
            Using gPath As New GraphicsPath()
                gPath.AddCurve(curve.Value.ToArray(), 0.5F)
                g.DrawPath(signaturePen, gPath)
            End Using
        Next
    End Sub
    Private Sub btnSaveSignature_Click(sender As Object, e As EventArgs) Handles btnSaveSignature.Click
        Dim signatureFileName = "Test1"
        If String.IsNullOrEmpty(signatureFileName) Then Return
        If currentCurve < 0 OrElse signatureObject(currentCurve).Count = 0 Then Return

        Dim imgSignature As Bitmap = New Bitmap(pBoxSignature.Width, pBoxSignature.Height, PixelFormat.Format32bppArgb)
        Using g As Graphics = Graphics.FromImage(imgSignature)
            DrawSignature(g)
            Dim signaturePath As String = Path.Combine(Application.StartupPath, $"{signatureFileName}.png")
            imgSignature.Save(signaturePath, ImageFormat.Png)
        End Using
    End Sub

    Private Sub pBoxSignature_Paint(sender As Object, e As PaintEventArgs) Handles pBoxSignature.Paint
        If currentCurve < 0 OrElse signatureObject(currentCurve).Count = 0 Then Return
        DrawSignature(e.Graphics)
    End Sub

End Class

Upvotes: -1

Views: 28

Answers (0)

Related Questions