首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Gambas3中,在图像JPG中写入文本

在Gambas3中,在图像JPG中写入文本
EN

Stack Overflow用户
提问于 2022-08-09 20:20:25
回答 2查看 58关注 0票数 0

我在Ubuntu20.04中使用Gambas3。我需要在图像中写一些文字,并创建一个新的图像。JPG o BMP

EN

回答 2

Stack Overflow用户

发布于 2022-08-10 20:02:39

我用这个代码解决了我的问题:将一个图像加载到绘图区域,然后绘制一个带有阴影的文本以获得最佳的可见度,然后以JPG格式保存,然后将新图像加载到其他绘图区域。不确定这是否是最好的选择,但它有效。

  • Gamba 3.17.3
  • Ubuntu 20.04
  • libs gb.gtk和gb.image
  • 图像大小800x533像素

我的代码:

代码语言:javascript
复制
' 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
票数 1
EN

Stack Overflow用户

发布于 2022-10-19 01:38:36

你把事情搞得太复杂了。

由于您可以直接使用图像和图片上的Paint.class,并且可以直接将图像加载到PictureBox中,所以您可以执行以下操作将图像加载到带有自定义文本的picturebox中.

代码语言:javascript
复制
  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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73297649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档