A 'NO IMAGE' water-mark!
Posted: Fri Mar 13, 2009 3:18 pm
Hi,
a basic image editor I am working with was in need of displaying a suitable message in place of an image when no image was defined etc. and so I grabbed some nice code of Bluid-fyte's (name obfuscated to preserve anonymity
) and turned it to my own needs!
The following will display any textual string in any square display area of your window (I just chose the whole window for convenience!) The underlying font will resize (courtesy of an Enhanced Metafile) quite nicely - better than attempting to use ResizeImage() etc.
This demo was knocked up in some haste so it is not very sophisticated :
a basic image editor I am working with was in need of displaying a suitable message in place of an image when no image was defined etc. and so I grabbed some nice code of Bluid-fyte's (name obfuscated to preserve anonymity


The following will display any textual string in any square display area of your window (I just chose the whole window for convenience!) The underlying font will resize (courtesy of an Enhanced Metafile) quite nicely - better than attempting to use ResizeImage() etc.
This demo was knocked up in some haste so it is not very sophisticated :
Code: Select all
;Based on code by Bluid-fyte.
text$ = "NO IMAGE DEFINED!"
If OpenWindow(0, 0, 0, 600, 600, "",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;Create an EMF to house the text.
hdc = CreateEnhMetaFile_(0, 0, 0, 0)
If hdc
oldBrush = SelectObject_(hdc, GetStockObject_(#NULL_BRUSH))
oldPen = SelectObject_(hdc, GetStockObject_(#WHITE_PEN))
SetBkMode_(hdc, #TRANSPARENT)
hFont = CreateFont_(100,55,450,0.0,0,0,0,0,0,0,0,0,0,"ARIAL")
oldFont = SelectObject_(hdc, hFont)
SetTextAlign_(hdc, #TA_LEFT|#TA_BOTTOM)
BeginPath_(hdc)
TextOut_(hdc, 70, 510,text$, Len(text$))
EndPath_(hdc)
SelectObject_(hdc, oldFont)
DeleteObject_(hFont)
StrokeAndFillPath_(hdc)
SelectObject_(hdc, oldPen)
SelectObject_(hdc, oldBrush)
hEMF = CloseEnhMetaFile_(hdc)
EndIf
width = WindowWidth(0)
height = WindowHeight(0)
;Now an image gadget etc.
If CreateImage(1, width, height, 24)
hdc = StartDrawing(ImageOutput(1))
If hdc
SetRect_(rc.RECT, 0, 0, width,height)
PlayEnhMetaFile_(hdc, hEMF, rc)
StopDrawing()
ImageGadget(1, 0,0,0,0,ImageID(1))
EndIf
EndIf
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
DeleteEnhMetaFile_(hEMF)
EndIf