Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help printing a scaled string in a custom font to a 32-bit image
#5
It's a case of missing OPTION EXPLICIT and *math*.   Tongue

Code: (Select All)
'Prints string MyString stretched to xScale%, yScale%
'in the current _FONT
'to 32-bit screen at ColNum%,RowNum%
'where the width  of 1 column is _FontWidth  * xScale%
'      and height of 1 row    is _FontHeight * yScale%
'with foreground color fg~& and background color bg~&

Screen _NewImage(1280, 720, 32)
$Color:32
DrawString "Hello World", Red, Blue, 10, 10, 2, 2



Sub DrawString (MyString As String, fg~&, bg~&, ColNum%, RowNum%, xScale%, yScale%)
    Dim SavedSource&
    Dim SavedDest&
    Dim MyImage&
    Dim FontHandle&
    Dim x1&, y1&, x2&, y2&, w1&, h1&

    ' remember the source / destination
    SavedSource& = _Source
    SavedDest& = _Dest

    ' get the font
    FontHandle& = _Font

    MyImage& = _NewImage(_UPrintWidth(MyString, , FontHandle&), _UFontHeight(FontHandle&), 32)
    _Dest MyImage&

    _Font FontHandle&
    Color fg~&, bg~& 'YOU NEED TO REFERENCE THE PROPER VARIABLE NAMES HERE.  SUFFIX!!!
    _UPrintString (0, 0), MyString, , , FontHandle&, MyImage&

    w1& = _Width(MyImage&) * xScale%
    h1& = _Height(MyImage&) * yScale%
    x1& = ColNum% * _FontWidth 'POSITION RELATIVE TO FONT SIZE
    y1& = RowNum% * _UFontHeight      'MAYBE WANT FONTHEIGHT HERE FOR POSITIONING?  IF SO, THEN PRINTSTING ABOVE
    x2& = x1& + w1&
    y2& = y1& + h1&

    _PutImage (x1&, y1&)-(x2&, y2&), MyImage&, SaveDest&

    ' Restore the source/destination
    _Source SavedSource&
    _Dest SavedDest&

    ' Cleanup

    _FreeImage MyImage&
End Sub ' DrawString

fg and bg are *undefined variables*, so you're setting a color of Transparent Black, Transparent Black...   That's going to kill everything to start with.  Tongue

Then the position of where you're trying to place the text is off, as you're trying to put it on pixel coordinates instead of text coordinates.
Reply


Messages In This Thread
RE: need help printing a scaled string in a custom font to a 32-bit image - by SMcNeill - 07-02-2025, 07:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Experimenting with a "StringList" type for simpler handling of string arrays/lists Heimdall 18 1,184 12-19-2025, 12:51 PM
Last Post: Heimdall
  Font Size in Threads Dimster 5 357 12-12-2025, 04:49 PM
Last Post: Dimster
  Sub not Reconizing Dim as String pmackay 18 1,448 10-16-2025, 03:32 PM
Last Post: pmackay
  error doing image collision detection with _MemGet madscijr 55 4,655 10-01-2025, 03:25 PM
Last Post: bplus
  Problem with font in Teletext browser. SquirrelMonkey 7 742 08-27-2025, 11:38 AM
Last Post: BDS107

Forum Jump:


Users browsing this thread: 2 Guest(s)