Page 1 of 1

DrawText() -- black font?

Posted: Mon Jul 29, 2013 11:18 am
by jassing
I have this code:

Code: Select all

nWidth=16:nHeight=16:nTemp.f=99.9

  hImage = CreateImage(#PB_Any, nWidth + 4, nHeight, 32, RGB(212,208,200))
  If StartDrawing(ImageOutput(hImage))
  	DrawText(1,1,StrF(nTemp,0));,RGB(0,0,0),RGB(254,254,254))
  	;Debug DrawText(1,1,StrF(nTemp,0),RGB(254,254,254),RGB(0,0,0))
  	
  	StopDrawing()
  endif 
My problem is, no matter what I do, I end up with a black box -- if I comment out the drawtext, an image with light gray is created. But I want to draw a black text on that image -- but I keep getting a black box appearing... I know this must be something stupid I'm missing (it's late here,3am, so sleep may help)

Re: DrawText() -- black font?

Posted: Mon Jul 29, 2013 11:30 am
by flood
The default font size is too big for the 20x16 image. So load a a smaller font, ie:

Code: Select all

nWidth=16:nHeight=16:nTemp.f=99.9
  LoadFont(0,"Arial",8)
  hImage = CreateImage(#PB_Any, nWidth + 4, nHeight, 32, RGB(212,208,200))
  If StartDrawing(ImageOutput(hImage))
     DrawingFont(FontID(0))
     ;DrawingMode(#PB_2DDrawing_Transparent) ; Uncomment for transparent BG
     DrawText(1,1,StrF(nTemp,0));,RGB(0,0,0),RGB(254,254,254))
     DrawText(1,1,StrF(nTemp,0),RGB(254,254,254),RGB(0,0,0))
     StopDrawing()
  EndIf 

Re: DrawText() -- black font?

Posted: Mon Jul 29, 2013 12:27 pm
by TI-994A
jassing wrote:...I want to draw a black text on that image...
Hello jassing. Like flood said, just set the drawing mode to transparent, and use a slightly smaller font, and you'll get your black text on the grey box: :wink:

Code: Select all

nWidth=16: nHeight=16: nTemp.f=99.9
LoadFont(0, "Arial", 8)
hImage = CreateImage(#PB_Any, nWidth + 4, nHeight, 32, RGB(212,208,200))
If StartDrawing(ImageOutput(hImage))
  DrawingFont(FontID(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(1, 1, StrF(nTemp,0), RGB(0,0,0))
  StopDrawing()
EndIf

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(1, #PB_Any, #PB_Any, 100, 100, "Test", wFlags)
SetWindowColor(1, RGB(100, 100, 200))
ImageGadget(2, 20, 20, 0, 0, ImageID(hImage))

While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend 

Re: DrawText() -- black font?

Posted: Mon Jul 29, 2013 3:22 pm
by jassing
Thanks! I'll give that a try.... was frustrated last night...
I knew it was something simple; but i don't think I'd have gotten that on my own.
Cheers!