Posts: 1,058
Threads: 367
Joined: Oct 2007
I am using systematically "OnScreenDisplay" to prepare and display on screen bitmap information.
I am aware of topic :
auto clip of desktop image
with which this information may be stored in a bitmapfile for later use.
I wonder whether there exists a routine to prepare this bitfile information off-line (ie. not necessarily displayed
on screen) and store in a bitmapfile for later use.
Many thanks in advance for any advice.
Posts: 12,073
Threads: 140
Joined: Dec 2002
What is "to prepare this bitfile information"? Is it about screen capturing?
Posts: 1,058
Threads: 367
Joined: Oct 2007
More specifically : I want to prepare a bitmap file, using ascii text, store it to clipboard and then paste it in an adobe acrobat file, action similar to inserting a stamp.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Like this?
Macro
Macro964
BSTR b="Text"
__MemBmp m.Create(1000 100)
RECT r; SetRect &r 0 0 1000 100
DrawTextW m.dc b b.len &r 0
if(OpenClipboard(_hwndqm)) EmptyClipboard; SetClipboardData(CF_BITMAP m.Detach); CloseClipboard
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you very much. Perfect!
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras, could you please advise on the way to enclose to be stored in clipboard in a rectangle? Many thanks.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Macro
Macro965
BSTR b="Text"
;create big memory DC
__MemBmp m.Create(1000 100)
;set font
__Font font.Create("Verdana" 14 2)
SelectObject m.dc font
;calculate text rectangle
RECT r; DrawTextW m.dc b b.len &r DT_CALCRECT|DT_EXPANDTABS|DT_NOPREFIX
;draw background and rectangle
OffsetRect &r 4 2
InflateRect &r 4 2
__GdiHandle brush=CreateSolidBrush(0xC0FFFF); SelectObject m.dc brush
__GdiHandle pen=CreatePen(0 2 0xff0000); SelectObject m.dc pen
Rectangle m.dc 1 1 r.right r.bottom
;draw text
SetBkMode m.dc TRANSPARENT
SetTextColor m.dc 0xff0000
InflateRect &r -4 -2
DrawTextW m.dc b b.len &r DT_EXPANDTABS|DT_NOPREFIX
;copy the rectangle to another memory DC (crop)
InflateRect &r 4 2
__MemBmp m2.Create(r.right r.bottom m.dc)
;bitmap to clipboard
if(OpenClipboard(_hwndqm)) EmptyClipboard; SetClipboardData(CF_BITMAP m2.Detach); CloseClipboard
Posts: 1,058
Threads: 367
Joined: Oct 2007
Thank you again for a perfect dynamic pdf stamp!
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras, I would appreciate it if you could extend your instructions regarding the procedure to add a small icon (.ico file) to this off-screen bitmap information. Many thanks in advance.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Use Windows API function DrawIconEx.
GetFileIcon - DrawIconEx - DestroyIcon.
Posts: 763
Threads: 261
Joined: Jul 2012
Is there a way to save directly to a file without using clipboard?
Currently I have this
Macro
Macro4
str ext="jpg"
str fname="test"
str infolder="$desktop$"
str sFile=F"{infolder}\{fname}.{ext}"
BSTR b="Text"
;create big memory DC
__MemBmp m.Create(1000 100)
;set font
__Font font.Create("Verdana" 14 2)
SelectObject m.dc font
;calculate text rectangle
RECT r; DrawTextW m.dc b b.len &r DT_CALCRECT|DT_EXPANDTABS|DT_NOPREFIX
;draw background and rectangle
OffsetRect &r 4 2
InflateRect &r 4 2
__GdiHandle brush=CreateSolidBrush(0xC0FFFF); SelectObject m.dc brush
__GdiHandle pen=CreatePen(0 2 0xff0000); SelectObject m.dc pen
Rectangle m.dc 1 1 r.right r.bottom
;draw text
SetBkMode m.dc TRANSPARENT
SetTextColor m.dc 0xff0000
InflateRect &r -4 -2
DrawTextW m.dc b b.len &r DT_EXPANDTABS|DT_NOPREFIX
;copy the rectangle to another memory DC (crop)
InflateRect &r 4 2
__MemBmp m2.Create(r.right r.bottom m.dc)
;bitmap to clipboard
if(OpenClipboard(_hwndqm))
,EmptyClipboard
,SetClipboardData(CF_BITMAP m2.Detach)
,;CloseClipboard
,_i=GetClipboardData(CF_BITMAP)
,__GdiHandle hb; if(_i) hb=CopyImage(_i 0 0 0 LR_CREATEDIBSECTION)
,CloseClipboard
,if(_i=0) end "no bitmap in clipboard"
,
,;save as jpg
,#compile "__Gdip"
,
,GdipBitmap im
,if(!im.FromHBITMAP(hb)) end "error"
,if(!im.Save(sFile)) end "error"
It is slightly modified with code from another example.
It works, but I do not know if code is "correct".
But would like to know if it is possible without using clipboard (save directly to file).
Posts: 8
Threads: 0
Joined: Mar 2018
How about this:
Macro
Macro47
str ext="jpg"
str fname="Test"
str infolder="$desktop$"
str sFile=F"{infolder}\{fname}.{ext}"
BSTR b="Test"
;create big memory DC
__MemBmp m.Create(1000 100)
;set font
__Font font.Create("Verdana" 14 2)
SelectObject m.dc font
;calculate text rectangle
RECT r; DrawTextW m.dc b b.len &r DT_CALCRECT|DT_EXPANDTABS|DT_NOPREFIX
;draw background and rectangle
OffsetRect &r 4 2
InflateRect &r 4 2
__GdiHandle brush=CreateSolidBrush(0xC0FFFF); SelectObject m.dc brush
__GdiHandle pen=CreatePen(0 2 0xff0000); SelectObject m.dc pen
Rectangle m.dc 1 1 r.right r.bottom
;draw text
SetBkMode m.dc TRANSPARENT
SetTextColor m.dc 0xff0000
InflateRect &r -4 -2
DrawTextW m.dc b b.len &r DT_EXPANDTABS|DT_NOPREFIX
;copy the rectangle to another memory DC (crop)
InflateRect &r 4 2
__MemBmp m2.Create(r.right r.bottom m.dc)
;save as jpg
#compile "__Gdip"
__GdiHandle hb=CopyImage(m2.Detach 0 0 0 LR_CREATEDIBSECTION)
GdipBitmap im
if(!im.FromHBITMAP(hb)) end "error"
if(!im.Save(sFile)) end "error"
Posts: 763
Threads: 261
Joined: Jul 2012
@TeddyBear
Yes that's it!
Thank you!