Page 1 of 1

A 'NO IMAGE' water-mark!

Posted: Fri Mar 13, 2009 3:18 pm
by srod
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 :wink: ) 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 :

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

Posted: Fri Mar 13, 2009 3:31 pm
by Kwai chang caine
Master SROD wrote:This demo was knocked up in some haste so it is not very sophisticated :
My dream ......can knocked up in some haste a day like this :roll:
Fluid and you have a good idea.
Before, i have creating a picture, nearly like this, for put in a place where there are not picture.
This code can be very usual :D

Or perhaps it's possible to add picture and text...
Like "SPECIMEN" or "NOT FOR SALE" or "COPYRIGHT" :roll:

Thanks for sharing 8)

Posted: Fri Mar 13, 2009 3:47 pm
by Fluid Byte

Code: Select all

;Based on code by Fluid-byte. 
... 'the hell? Which code? :o

Posted: Fri Mar 13, 2009 6:26 pm
by srod
Fluid Byte wrote:

Code: Select all

;Based on code by Fluid-byte. 
... 'the hell? Which code? :o
http://www.purebasic.fr/english/viewtop ... =beginpath

Posted: Fri Mar 13, 2009 6:32 pm
by Fluid Byte
Oldskool ... :shock:

Posted: Fri Mar 13, 2009 6:36 pm
by srod
Fluid Byte wrote:Oldskool ... :shock:
It did the trick! I've never used BeginPath_() before and it was just what I was looking for! Credit where credit is due... course I can remove your name if you wish? :wink:

Posted: Fri Mar 13, 2009 6:42 pm
by rsts
Very nice.

Thanks to you both :D

cheers

Posted: Fri Mar 13, 2009 6:55 pm
by Fluid Byte
srod wrote:course I can remove your name if you wish? :wink:
Go ahead. I don't want my name to be associated with that mess. :wink:

Posted: Fri Mar 13, 2009 6:57 pm
by srod
Fluid Byte wrote:
srod wrote:course I can remove your name if you wish? :wink:
Go ahead. I don't want my name to be associated with that mess. :wink:
Done! :wink: