Picture Class - consoleApp

Hi,

I am trying to generate an image in a console app in which the goal is to use the graphics class to draw on the picture and then save it as jpg on disk. If I run the code below in a desktop app, it produces the image correctly and the text is visible. If I take the same code and put in a console app, the text is not visible. Is there a limitation in console app here?

[code]
dim picDCM as picture = new Picture(500, 500)

picDCM.Graphics.ForeColor = &c000000
picDCM.Graphics.FillRect 0,0,500,500

dim outputText As New StringShape

outputText.Text = “this is a test”
outputText.TextFont = “Courier”
outputText.TextSize = 16
outputText.Bold= True
outputText.FillColor = &cFFFFFF
outputText.X = 10
outputText.Y = 20
outputText.HorizontalAlignment = StringShape.Alignment.Left
picDCM.Graphics.DrawObject outputText

dim f as FolderItem = SpecialFolder.Desktop.child(“testtest.jpg”)

picDCM.Save(f, Picture.SaveAsJPEG)[/code]

My guess is: no GUI = no Fonts.

picture & graphics should be usable in a console app like this
maybe the console app isnt finding the font for some reason ?

Great observation norm!

I changed it to Arial, and text displays.

What platform are you on. I have a “Courier New” on my Winblows 10 installation. If you change the font to “Courier New”, does that work? Of on another platform, adjust font name as appropriate.

Next time, before guessing, I should test the code :slight_smile:

This what I get on macOS 10.12.6 using the code as is:

Edit: don’t know why the font looks italic and not bold, changing “Courier” to “Courier New” fixed that.

I am on windows 10.

I changed to Ariel, which works fine. thank you everyone

ConsoleApplications indeed cannot easily access all fonts, see <https://xojo.com/issue/49033>

You can list all available fonts using: FontCount and Font global Methods.

When dealing with Text in ConsoleApplications, be aware of rendering differences compared to Desktop Applications: <https://xojo.com/issue/38272> Further TextUnit seem to be dysfunctional and the effective value is always Pixel, so calculate your TextSize accordingly: <https://xojo.com/issue/26147> and StringHeight seems to be broken in a way I wasn’t able to understand.

Further reading: Web vs Desktop picture.graphics drawing fontsize difference - Web - Xojo Programming Forum