May 31, 2020, 09:19:33 PM

Author Topic: Writing text to a TImage  (Read 121 times)

Offline _PJ_

  • Jr. Member
  • **
  • Posts: 65
Writing text to a TImage
« on: May 16, 2020, 03:25:26 PM »
To mimic the old B+ "SetBuffer" equivalent:
Local OriginalBuffer=GraphicsBuffer()
Local T$ = "FooBar"
Local TW = StringWidth(T)
Local TH = StringHeight(T)
Local Image = CreateImage(TW,TH)
Local Buffer = ImageBuffer(Image)
SetBuffer Buffer
Text (TW * 0.5),TH * 0.5, T , 1, 1
SetBuffer OriginalBuffer

it seems there is no GetCurrentGraphicsObject() function so I need to store the original GraphicsObject when its created in order to re - SetGraphics after I've finished...

Global G:TGraphics = Graphics(…..)

Local T:String = "FooBar"
Local TW:Int = TextWidth(T)
Local TH:Int = TextHeight(T)
Local Image:TImage = CreateImage(TW,TH)

And now I am stuck, since although there are LockImage and LoadPixmap functions that can allow access to the image for pixel editing, I am not sure how to actually set the Image "buffer" as a graphics object to which I can apply DrawText command.

If anyone has any suggestions or advice as to how to achieve this, I will be most grateful, thank you.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2975
Re: Writing text to a TImage
« Reply #1 on: May 16, 2020, 10:49:33 PM »
Render2Texture (there exists codes in the archive)
I also did modify the code of Col to incorporate it into max2D but for weeks nobody even dared to bug test it:

Another option is to use my bitmapfont class - it has the option to set a image as render target (software rendering).

Maybe you want to copy some bits from it - should be pretty straight forward to make it work with standard TImageFont (which has "glyphs" for each char - which are single TImage objects).

Render2Texture is the best option as it handles all the rotation, blends, scaling, ... for you.


Offline _PJ_

  • Jr. Member
  • **
  • Posts: 65
Re: Writing text to a TImage
« Reply #2 on: May 17, 2020, 10:32:54 AM »
Thanks, Derron.
Looks like that's exactly what I need!

I will see how I get on with this. Thank you.


SimplePortal 2.3.6 © 2008-2014, SimplePortal