use
Code: Select all
MouseClickDrag
or
Code: Select all
SendEvent {Click 6, 52, down}{click 45, 52, up}
Code: Select all
text:=OCR(x,y,x1,y1)
Code: Select all
MouseClickDrag
Code: Select all
SendEvent {Click 6, 52, down}{click 45, 52, up}
Code: Select all
text:=OCR(x,y,x1,y1)
Code: Select all
DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
Code: Select all
Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75)
Code: Select all
fileName := A_YYYY "-" A_MM "-" A_DD "-" A_Hour "-" A_Min "-" A_Sec ".png"
pBitmap := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen()
saveFileTo := fileName
Gdip_SaveBitmapToFile(pBitmap, saveFileTo)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pBitmap)
Code: Select all
Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75)
{
Ptr := A_PtrSize ? "UPtr" : "UInt"
nCount := 0
nSize := 0
_p := 0
SplitPath sOutput,,, Extension
if !RegExMatch(Extension, "^(?i:BMP|DIB|RLE|JPG|JPEG|JPE|JFIF|GIF|TIF|TIFF|PNG)$")
return -1
Extension := "." Extension
DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
VarSetCapacity(ci, nSize)
DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
if !(nCount && nSize)
return -2
If (A_IsUnicode){
StrGet_Name := "StrGet"
N := (A_AhkVersion < 2) ? nCount : "nCount"
Loop %N%
{
sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
if !InStr(sString, "*" Extension)
continue
pCodec := &ci+idx
break
}
} else {
N := (A_AhkVersion < 2) ? nCount : "nCount"
Loop %N%
{
Location := NumGet(ci, 76*(A_Index-1)+44)
nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
if !InStr(sString, "*" Extension)
continue
pCodec := &ci+76*(A_Index-1)
break
}
}
if !pCodec
return -3
if (Quality != 75)
{
Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
if RegExMatch(Extension, "^\.(?i:JPG|JPEG|JPE|JFIF)$")
{
DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
VarSetCapacity(EncoderParameters, nSize, 0)
DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
nCount := NumGet(EncoderParameters, "UInt")
N := (A_AhkVersion < 2) ? nCount : "nCount"
Loop %N%
{
elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
{
_p := elem+&EncoderParameters-pad-4
NumPut(Quality, NumGet(NumPut(4, NumPut(1, _p+0)+20, "UInt")), "UInt")
break
}
}
}
}
if (!A_IsUnicode)
{
nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
VarSetCapacity(wOutput, nSize*2)
DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
VarSetCapacity(wOutput, -1)
if !VarSetCapacity(wOutput)
return -4
_E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", _p ? _p : 0)
}
else
_E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", _p ? _p : 0)
return _E ? -5 : 0
}
Yes, it worked.. I am just wondering what happened in background that created this issue?
That is awesome that you can do that. I am happy for you. I am wondering why write another one if GDIP exists? My level is no where near of creating library like that or working with DLL calls, but I am learning slowly..I wrote a new image library to do what you're doing now
I think the use of screen coordinates is baked into the GDip library used by Vis2. Your best bet is probably to do something like this:
Code: Select all
WindowOCR(x1,y1,x2,y2, windowName)
{
WinActivate, %windowName%
WinGetPos, WinX,WinY,,,,,,
x := WinX + x1
y := WinY + y1
w := x2-x1
h := y2-y1
coords := [x,y,w,h]
return OCR(coords)
}
Was looking for something similar, but as tom098656 solution didn't work for me(cuz I suck at coding) I used WinActivate.
Code: Select all
Q::
if WinExist("ahk_exe BlueStacks.exe")
WinActivate ; use the window found above
OCR("A", ,[77, 682, 741, 800]).clipboard()
WinExist("ahk_exe firefox.exe") ; back to firefox
WinActivate ; use the window found above
return
Afaik, there are third-party pdf-to-text tools available on the interwebs (but I haven't use one (at least not recently), I don't know how they'd handle pdfs with restricted rights), which do not rely on OCR, I think.
Yes! (thanks)
Code: Select all
FileAppend % OCR(imgFile, "swe", [200,700,100,75]), %resFile%
Code: Select all
MsgBox % OCR("text.jpg")
Code: Select all
MsgBox % OCR("text.jpg", "swe", [x,y,w,h])
Code: Select all
#include <Vis2>
HS = 2
F11::
Highlight(HS)
Highlight(TH)
{
local
if (x="")
{
VarSetCapacity(pt,16,0), DllCall("GetCursorPos","ptr",&pt)
x:=NumGet(pt,0,"uint"), y:=NumGet(pt,4,"uint")
}
x:=Round(x), y:=Round(y)
w = 25
h = 25
Gui, +LastFound +ToolWindow -Caption +AlwaysOnTop
Gui, Color, Red
Gui, Show, x%X% y%Y% w%W% h%H% Hide
Options := "0-0 " W "-0 " W "-" H " 0-" H " 0-0 " TH "-" TH
. " " W-TH "-" TH " " W-TH "-" H-TH " " TH "-" H-TH " " TH "-" TH
WinSet, Region, % Options
Gui, Show, NA
KeyWait, F11
Gui, Destroy
}
text := OCR([%x%, %y%, %w%, %h%])
msgBox, % text
return
Esc:: ExitApp
I had perceived it that way (in the end)
Return to “Scripts and Functions (v1)”
Users browsing this forum: No registered users and 69 guests