Save drawn Image to file
I want my programm to save an Text as Image to a file. This is what I could do so far:
Public Sub StringToPrint()
Me.Refresh()
Dim formGraphics As Graphics = PictureBox1.CreateGraphics() 'draw text to PictureBox1
Dim drawString As String = TextBox1.Text
Dim drawFont As System.Drawing.Font = New System.Drawing.Font("Arial", 16)
Dim drawBrush As System.Drawing.SolidBrush = New System.Drawing.SolidBrush(System.Drawing.Color.Black)
Dim drawFormat As System.Drawing.StringFormat = New System.Drawing.StringFormat()
formGraphics.DrawString(drawString, drawFont, drawBrush, New PointF(0, 0), drawFormat)
formGraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
formGraphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
formGraphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
' Save the screenshot This part right here is not working...
'SaveFileDialog1.Filter = "JPEG Files (*.jpeg*)|*.jpeg"
'If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK _
' Then
' 'PictureBox1.Image.Save(SaveFileDialog1.FileName, ImageFormat.Jpeg)
'End If 'It says PcitureBox1 is Nothing.
drawFont.Dispose()
drawBrush.Dispose()
formGraphics.Dispose()
End Sub
I only want to save the Text in the PictureBox1 as a transparent image file.