I use Gambas3 in Ubuntu 20.04. I need write some text in a image and create a new image. JPG o BMP
In Gambas3 write text inside a Image JPG o BMP
240 Views Asked by Alejandro Bergesio At
2
There are 2 best solutions below
0
On
You have over-complicated it I think.
As you can use the Paint.class on Images and pictures directly and as you can load an Image directly into a PictureBox you could simply do the following to load an image into a picturebox with custom text...
Public Sub btnSetImage_Click()
Dim hImage As Image
Dim sText As String = "Hello World 12.345"
hImage = Image.Load("bird212.jpg")
Paint.Begin(hImage)
Paint.Font = Font["Mono, 12, bold"]
Paint.Background = Color.White
Paint.DrawRichTextShadow(sText, 0, hImage.Height - Paint.Font.Height * 2, Me.Width, Paint.Font.Height, Align.Center,, 1)
Paint.Stroke
Paint.Background = Color.black
Paint.DrawRichText(sText, 0, hImage.Height - Paint.Font.Height * 2, Me.Width, Paint.Font.Height, Align.Center)
Paint.End
Try PictureBox2.Image.Clear
PictureBox2.Image = hImage
End
Public Sub btnSaveImage_Click()
PictureBox2.Picture.Save(user.home &/ "prub.jpg")
Label1.text = "Image saved in: " & user.home &/ "prub.jpg"
End
I resolve my problem with this code; load a image into drawing area, then draw a text with shadow for best visibility, then save in format JPG, and then load the new image into other drawing area. Not sure if this is the best option, but it works.
My code: