我在Ubuntu20.04中使用Gambas3。我需要在图像中写一些文字,并创建一个新的图像。JPG o BMP
发布于 2022-08-10 20:02:39
我用这个代码解决了我的问题:将一个图像加载到绘图区域,然后绘制一个带有阴影的文本以获得最佳的可见度,然后以JPG格式保存,然后将新图像加载到其他绘图区域。不确定这是否是最好的选择,但它有效。
我的代码:
' Gambas class file
Public Sub Form_Open()
DrawingArea1.Background = Color.white
End
Public Sub DrawingArea1_Draw()
dibu()
End
Private Sub dibu()
Dim X, Y, W, H As Float
Dim hBrush As PaintBrush
Dim hImage As Image
hImage = Image.Load("bird212.jpg")
X = 0
Y = 0
W = 800
H = 533
hBrush = Paint.Image(hImage)
hBrush.Translate(X, Y)
Paint.Brush = hBrush
Paint.Rectangle(X, Y, W, H)
Paint.Fill
Paint.Stroke
Paint.Font.Name = "Mono"
Paint.Font.Size = 12
Paint.Font.Bold = True
Paint.Brush = Paint.Color(Color.White)
Paint.DrawRichTextShadow("Hello WORLD 12.345", 10, 500, 300, 50,,, 1)
Paint.Fill
Paint.Stroke
Paint.Brush = Paint.Color(Color.Black)
Paint.DrawRichText("Hello WORLD 12.345", 10, 500, 300, 50)
Paint.Fill
Paint.Stroke
End
Public Sub ButtonSaveImage_Click()
Dim filex As Picture
filex = New Picture(drawingArea1.w, drawingArea1.h, Color.Transparent) 'probar...
Paint.begin(filex)
dibu()
paint.end
filex.save(user.home & "/" & "prub.jpg")
Label1.text = "Image saved in: " & user.home & "/" & "prub.jpg"
PictureBox2.Picture = Picture.Load(user.home & "/" & "prub.jpg")
End发布于 2022-10-19 01:38:36
你把事情搞得太复杂了。
由于您可以直接使用图像和图片上的Paint.class,并且可以直接将图像加载到PictureBox中,所以您可以执行以下操作将图像加载到带有自定义文本的picturebox中.
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"
Endhttps://stackoverflow.com/questions/73297649
复制相似问题