Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prepare "off-screen" bitmap information
#12
How about this:

Macro Macro47
Code:
Copy      Help
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"


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)