Hello,
I am trying to put a text string on a bitmap picture and not getting it to work.
I am using FW 25.12 + Harbour + BCC7.70.
This is what I am trying to do:
- Open existing BMP file.
- Add a transparent Text string to the BMP.
- Save new BMP file (with Text on it).
The picture does not even need to be displayed.
This is a sample from ChatGPT.
I pass in a BMP File Name and a Text String.
// TBitmap Version
Function AddReceipt2BMP(m_BMP,m_Receipt)
Local oBmp
Local oDC
Local hOldBmp
Local hFont
Local hOldFont
//Load BMP
oBmp := TBitmap():Define(m_BMP)
IF oBMP == NIL
// Can't open BMP File, Get Out!
Return
EndIf
// Memory DC (No idea what this does)
oDC := CreateCompatibleDC( 0 )
hOldBmp := SelectObject( oDC:hDC, oBmp:hBitmap ) // Errors on this Line!!!!!!
// Set drawing attributes
SetBkMode( oDC:hDC, 1 ) // Transparent
SetTextColor( oDC:hDC, CLR_YELLOW )
// Create Font
hFont := CreateFont(-28,0,0,0,700,0,0,0,ANSI_CHARSET,0,0,0,0,"Courier New")
hOldFont := SelectObject(oDC:hDC, hFont)
//Draw Text
TextOut(oDC:hDC, hOldFont,40,40,m_Receipt,len(m_Receipt))
// Cleanup font
SelectObject( oDC:hDC, hOldFont )
DeleteObject( hFont )
// Restore bitmap
SelectObject( oDC:hDC, hOldBmp )
// Save bitmap
oBmp:SaveToFile( "output.bmp" )
DeleteDC( oDC:hDC )
oBmp:End()
Return
I get an Error on -> hOldBmp := SelectObject( oDC:hDC, oBmp:hBitmap )
Error description: Error BASE/1004 No exported method: HDC
Does anyone have a sample function to add text to a BMP??
Thanks,
Brad Maudlin