A 'NO IMAGE' water-mark!

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

A 'NO IMAGE' water-mark!

Post 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
Last edited by srod on Fri Mar 13, 2009 6:57 pm, edited 2 times in total.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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)
ImageThe happiness is a road...
Not a destination
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Code: Select all

;Based on code by Fluid-byte. 
... 'the hell? Which code? :o
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Oldskool ... :shock:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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:
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Very nice.

Thanks to you both :D

cheers
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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:
I may look like a mule, but I'm not a complete ass.
Post Reply