03-25-2018, 09:01 PM
Is there a way to save directly to a file without using clipboard?
Currently I have this
Macro Macro4
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).
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).