I’m trying to write some text over an image but with no success. In the code snippet below I load a file, clear the lower right quadrant, write a couple of strings and save the image to a new file.
The new file is written and it contains the loaded image with the correctly cleared quadrant but no text is written.
This is a web app running on a Raspberry Pi. I have commented out the assignment to p.Graphics.TextUnit because it gives me an error message saying that
Dim p As Picture
p = Picture.Open(LatestImage)
Dim data As String = "LL: " + Str(Sample.Light) + " ISO: " + Str(iso) + " SS: " + Str(speed)
p.Graphics.ForeColor = &cff0000
p.Graphics.TextFont = "Helvetica"
//p.Graphics.TextUnit = FontUnits.Point
p.Graphics.TextSize = 16
p.Graphics.ClearRect(p.Graphics.Width/2, p.Graphics.Height/2, p.Graphics.Width, p.Graphics.Height)
p.Graphics.DrawString("Hello world", 10, 130)
p.Graphics.DrawString(data, 30, 30)
Dim tmp As FolderItem
tmp = New FolderItem( "/home/pi/Xojo/SkyCamImages/text.png")
If p.IsExportFormatSupported(Picture.FormatPNG) Then
System.Log(System.LogLevelDebug, "PNG Export not supported")
Lines 2 and 3: This item does not exists.
These certainly are the does not exists:
Please, set the Channel to Web or Raspberry Pi.
This code is just a snippet from a much larger program. Those variables do exist in my program and it compiles and runs - it just doesn’t behave as expected.
I set the channel to “Getting Started” because I am a Xojo novice but I will change it if you think my problem is either web or Raspberry Pi specific.
My assumption was that I was making a more generic error with regard to writing text onto a picture.
The most likely scenario is that you dont have Helvetica installed in the pi. Try using System first to make sure drawing is working (although that will still fail if no fonts are installed).
Thanks Greg, that was the issue.
Any idea why I can’t access the TextUnit property of the Graphics object?
[quote=404800:@Peter Lawrence]Thanks Greg, that was the issue.
Any idea why I can’t access the TextUnit property of the Graphics object?[/quote]
TextUnit is not available to the Console/Web Graphics object at this time.
You can get close though. Points & Pixels are darn near the same @72 dpi. If you need to work in another resolution, you can do some simple math:
Assuming you wanted 24pt text @ 150dpi…
dim Rez as Integer = 150
Dim mult as double = Rez / 72.0
Dim fontsize as double = 24
G.textsize = fontsize * mult