Picture Class - consoleApp

  1. 4 months ago

    Rich H

    Jun 5 Pre-Release Testers, Xojo Pro

    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?

    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)

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

  2. Alberto D

    Jun 5 Pre-Release Testers

    My guess is: no GUI = no Fonts.

  3. Norman P

    Jun 5 Pre-Release Testers, Xojo Pro Answer great-white-software.com/blog

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

  4. Rich H

    Jun 5 Pre-Release Testers, Xojo Pro

    Great observation norm!

    I changed it to Arial, and text displays.

  5. Kevin C

    Jun 5 Pre-Release Testers Georgia, USA

    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.

  6. Alberto D

    Jun 5 Pre-Release Testers
    Edited 4 months ago

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

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

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

  7. Rich H

    Jun 5 Pre-Release Testers, Xojo Pro

    I am on windows 10.

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

  8. Tobias B

    Jun 11 Pre-Release Testers, Xojo Pro Bern, Switzerland
    Edited 4 months ago

    ConsoleApplications indeed cannot easily access all fonts, see Feedback Case #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: Feedback Case #38272 Further TextUnit seem to be dysfunctional and the effective value is always Pixel, so calculate your TextSize accordingly: Feedback Case #26147 and StringHeight seems to be broken in a way I wasn't able to understand.

    Further reading: https://forum.xojo.com/49815-web-vs-desktop-picture-graphics-drawing-fontsize-difference

or Sign Up to reply!