str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 199 91 "Capture an Image"
;3 Button 0x54032000 0x0 40 9 129 30 "3. OUTPUT POINTS DRAGGED AREA DESKTOP"
;4 Button 0x54032000 0x0 39 49 130 32 "4. SCREENSHOT DRAG"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,,RECT- r
,,EnableWindow id(3 hDlg) 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,,out r.left
,,out r.top
,,out r.right
,,out r.bottom
,case 4
,,__GdiHandle hb
,,if(!CaptureImageOrColor(hb 0 hDlg "" r)) ret
,,mkdir "QM_CaptureImages" "$desktop$";;create folder if it doesnt exist to save images in
,,str sFolderName = "$desktop$\QM_CaptureImages\"
,,str sFileName.timeformat("{yyyy-MM-dd}_{HH-mm-ss}_QmCapture");;unique filename to avoid problems
,,str sFormat = ".png";;i use png for smaller filesize
,,str sFile.format("%s%s%s" sFolderName sFileName sFormat)
,,;save image
,,#compile "__Gdip"
,,GdipBitmap im
,,if(!im.FromHBITMAP(hb)) end "error"
,,if(!im.Save(sFile)) end "error"
,,_s=sub.ocr(sFile)
,,ShowText("Recognition result" _s)
,,EnableWindow id(3 hDlg) 1
,case IDOK
,case IDCANCEL
ret 1
#sub ocr
function~ ~name
typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1; WinHttp.WinHttpRequest r._create; r.Open("POST" F"https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"); r.setRequestHeader("content-type", "application/x-www-form-urlencoded"); r.SetRequestHeader("cache-control" , "no-cache")
str access= "access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329&image="
out name
str sFile.getfile(F"{name}");; change to file location
_s.encrypt(4 sFile "" 2); _s.escape(9); r.Send(F"{access}{_s}")
ARRAY(byte) a=r.ResponseBody; str s.fromn(&a[0] a.len)
IXml x=JsonToXml(s); ARRAY(IXmlNode) a1; x.Path("root/words_result/item/words" a1 1)
int i
str d
for(i 0 a1.len)
,d.formata("%s[]" a1[i].Value)
ret d.trim
didn't change much just added code to convert bitmap to png and save as a unique filename.
requires GDI+ get it here-->> Get GDI+