I'm having some trouble achieving some drawing in images in visual basic. I would like to write text totally centered in the image as automatic as possible. The best I can achieve is start the writing in the middle of the image. I would like the text centered in the image.
What I have right now:
Try
Dim ficheiro As New WebClient
Dim file = TextBox1.Text & "\" & jss.hits(Index).id & ".jpg"
ficheiro.DownloadFile(jss.hits(Index).webformatURL, file)
ficheiro.Dispose()
Dim bmp As New Bitmap(Image.FromFile(file))
Dim g As Graphics = Graphics.FromImage(bmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
Dim drawFormat As New StringFormat()
drawFormat.Alignment = StringAlignment.Center
g.DrawString(strarr(1), New Font("Montserrat Bold", 20), Brushes.White, New RectangleF(0, bmp.Height / 2, bmp.Width, bmp.Height), drawFormat)
Dim newpath = TextBox2.Text & "\" & strarr(0)
If (Not System.IO.Directory.Exists(newpath)) Then
System.IO.Directory.CreateDirectory(newpath)
End If
bmp.Save(newpath & "\" & jss.hits(Index).id & ".jpg")
Catch ex As Exception
MsgBox(ex.Message)
End Try
As an output:
As you can see, it starts the text in the middle of the image. I would like to get the center of the text, centered in the image. The text and image size could change, so it would be nice to automatically change the font size to fit the image if possible.
Also, after this, I would like to add another line, after this text, but starting in the middle to right only. I can't figure how I could do it. Thanks.