Hello,
I am trying to:
1. Search for an image <- Should be able with ImageSearch
2. I want to clip a bigger part of the screen containing the image I searched for <- I should be able to use the ImageSearch coords and extrapolate the coords for the bigger clip
3. "Take" that (bigger) image and show it on the screen in another location.
The question is how do I "copy" the image from the screen and show it in another place ?
Thank you!
Search Image & Show it elsewhere
Re: Search Image & Show it elsewhere
Thanks! I will try it out!
Re: Search Image & Show it elsewhere
I used that example (works fine) and tried to show the snap into a GUI (my target being to see that on the screen in another place)
I used the standard GUI .. adding the snap as bitmnap
Unfortunately the bitmap was not visible in GUI ... I guess I a missing something ...
Full code ...
I used the standard GUI .. adding the snap as bitmnap
Code: Select all
Gui, Add, Pic, w300 h-1, snap
Gui, Show
Full code ...
Code: Select all
#include lib\Gdip_All.ahk ; Replace with your GDI path
out = test.png ; Replace as needed
CoordMode, Mouse
F3:: ; Hold F3 to make a selection, then release
MouseGetPos, x1, y1
SoundBeep, 1500, 20
KeyWait, %A_ThisHotkey%
SoundBeep, 1000, 20
MouseGetPos, x2, y2
width := x2 - x1, height := y2 - y1
If (width < 4 && height < 4)
Return
pToken := Gdip_Startup(),
snap := Gdip_BitmapFromScreen(x1 "|" y1 "|" width "|" height)
Gdip_SetBitmapToClipboard(snap),
Gdip_SaveBitmapToFile(snap, out)
Gui, Add, Pic, w300 h-1, snap
Gui, Show
Gdip_DisposeImage(snap),
Gdip_Shutdown(pToken)
Return
Re: Search Image & Show it elsewhere
Does anyone have a hint on the reason why the bitmap is not showing on GUI ?
Re: Search Image & Show it elsewhere
In your Add, Pic, change snap to %out%, which is the path to the image file.
Re: Search Image & Show it elsewhere
Thanks - works!
PS: I was hoping I dont need to save to a file, but this will work as well!
PS: I was hoping I dont need to save to a file, but this will work as well!
Re: Search Image & Show it elsewhere
It could be a temporary file that is deleted later, of course.The last parameter is the filename of the image, which is assumed to be in A_WorkingDir if an absolute path isn't specified.
Re: Search Image & Show it elsewhere
Yes of course ...
Actualy I will do this every 200-500 ms so I hope will work ok with files
PS: I am trying to show a "status" in a better postion on the screen and as I cant change the original layout I am practicaly tryin to duplicate and refresh constantly ...
Actualy I will do this every 200-500 ms so I hope will work ok with files
PS: I am trying to show a "status" in a better postion on the screen and as I cant change the original layout I am practicaly tryin to duplicate and refresh constantly ...
Re: Search Image & Show it elsewhere
Below is an example without files.
Code: Select all
#include lib\Gdip_All.ahk ; Replace with your GDI path
CoordMode, Mouse
F3:: ; Hold F3 to make a selection, then release
MouseGetPos, x1, y1
SoundBeep, 1500, 20
KeyWait, %A_ThisHotkey%
SoundBeep, 1000, 20
MouseGetPos, x2, y2
width := x2 - x1, height := y2 - y1
If (width < 4 && height < 4)
Return
pToken := Gdip_Startup()
snap := Gdip_BitmapFromScreen(x1 "|" y1 "|" width "|" height)
Gui, New
; https://www.autohotkey.com/boards/viewtopic.php?p=117639#p117639
Gui, Add, Pic,, % "HBITMAP:*" Gdip_CreateHBITMAPFromBitmap(snap)
Gui, Show
Gdip_DisposeImage(snap), Gdip_Shutdown(pToken)
Return
Re: Search Image & Show it elsewhere
Oh, nice!
Thanks a lot for taking the time!
Thanks a lot for taking the time!
Re: Search Image & Show it elsewhere
Hi,
I advanced pretty decent, but I do have a problem.
I am trying to update the bitmap every 250 miliseconds, however it does not refresh.
I assume there is something I am missing to refresh/redraw the GUI.
MainAgro is started by a Key and shows the bitmap from a location to the middle of the screen.
UpdateGui shows correctly the first bitmap but does not update after ...
I advanced pretty decent, but I do have a problem.
I am trying to update the bitmap every 250 miliseconds, however it does not refresh.
I assume there is something I am missing to refresh/redraw the GUI.
MainAgro is started by a Key and shows the bitmap from a location to the middle of the screen.
UpdateGui shows correctly the first bitmap but does not update after ...
Code: Select all
MainAgro(){
CustomColor := "EEAA99"
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
WinSet, TransColor, %CustomColor% 200
SetTimer, UpdateGui, 250
Gosub, UpdateGui
Gui, Show, NoActivate
Return
}
UpdateGui:
If (width < 4 && height < 4)
Return
pToken := Gdip_Startup()
snap := Gdip_BitmapFromScreen(AgroBarMainX1 "|" AgroBarMainY1 "|" width "|" height)
Gui, Add, Pic,Y++250 w75 h-1, % "HBITMAP:*" Gdip_CreateHBITMAPFromBitmap(snap)
Gdip_DisposeImage(snap), Gdip_Shutdown(pToken)
return
Re: Search Image & Show it elsewhere
GuiControl can be used to change the contents of a GUI control.
Code: Select all
#include q:\vis2\lib\Gdip_All.ahk
Global snap
pToken := Gdip_Startup()
updateGUI(50, 50, 200, 100)
Sleep, 1000
updateGUI(150, 150, 200, 100)
Return
updateGUI(x, y, width, height){
Static pic, started := False
snap := Gdip_BitmapFromScreen(x "|" y "|" width "|" height)
hbitmap := Gdip_CreateHBITMAPFromBitmap(snap), image := "HBITMAP:*" hbitmap
If started
GuiControl,, pic, %image%
Else
Gui, Add, Picture, w200 h100 vpic, %image%
started := True
Gui, Show
}
F4::
Gdip_DisposeImage(snap), Gdip_Shutdown(pToken)
ExitApp
Re: Search Image & Show it elsewhere
Works like a charm!
Thank you!
Thank you!
Code: Select all
MainAgro(){
CustomColor := "EEAA99"
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
WinSet, TransColor, %CustomColor% 200
SetTimer, UpdateOSD, 250
updateGUI(AgroBarMainX1,AgroBarMainY1, gwidth, gheight)
Return
}
UpdateOSD:
result := updateGUI(AgroBarMainX1,AgroBarMainY1, gwidth, gheight)
return
updateGUI(x, y, width, height){
Static pic, started := False
snap := Gdip_BitmapFromScreen(x "|" y "|" width "|" height)
hbitmap := Gdip_CreateHBITMAPFromBitmap(snap), image := "HBITMAP:*" hbitmap
If started
GuiControl,, pic, %image%
Else
Gui, Add, Picture, Y++250 w75 h-1 vpic, %image%
started := True
Gui, Show
return
}
Re: Search Image & Show it elsewhere
No problem.
You have an unintended effect in your update function: the following lines are always executed.
That is because in AHK, braces, rather than indentation, define a code block. Your Else "block" contains no braces, so the only line attached to Else is the same line or, if that line contains nothing else, the line that follows it.
It turns out, in your particular script here, that it doesn't matter if those two lines are executed with each call to the function. You actually don't need either of them to execute after the first run, but they serve no purpose in those subsequent runs.
A couple of other little tweaks in case you are interested in fine tuning:
1. CustomColor := "EEAA99" is OK but can also be preceded by Static. This prevents the need to redefine that variable during each function call. You won't see any difference directly in your script; it's more of a technicality. In some scripts, it may matter.
2. Return without returning anything-- as a function's last command-- has no effect and can be deleted. The function will still return upon the closing brace. In both instances, nothing will be returned, so Return has no effect.
You have an unintended effect in your update function: the following lines are always executed.
Code: Select all
started := True
Gui, Show
It turns out, in your particular script here, that it doesn't matter if those two lines are executed with each call to the function. You actually don't need either of them to execute after the first run, but they serve no purpose in those subsequent runs.
A couple of other little tweaks in case you are interested in fine tuning:
1. CustomColor := "EEAA99" is OK but can also be preceded by Static. This prevents the need to redefine that variable during each function call. You won't see any difference directly in your script; it's more of a technicality. In some scripts, it may matter.
2. Return without returning anything-- as a function's last command-- has no effect and can be deleted. The function will still return upon the closing brace. In both instances, nothing will be returned, so Return has no effect.
Re: Search Image & Show it elsewhere
Nice points - thank you.
On Return I've seen it used in a few examples using this without a return value ... I was wondering about its utility, but I guess others are picking this up and using it ... like I did
.......
I was happy that I finished but ... it seems that when the timmer is active the active window does not get any input from my keyboard.
I think is because I keep the CPU busy ... and gave a few Sleep between the commnds, so seems ok now ..
On Return I've seen it used in a few examples using this without a return value ... I was wondering about its utility, but I guess others are picking this up and using it ... like I did
.......
I was happy that I finished but ... it seems that when the timmer is active the active window does not get any input from my keyboard.
I think is because I keep the CPU busy ... and gave a few Sleep between the commnds, so seems ok now ..
Code: Select all
MainAgro(){
static CustomColor := "EEAA99"
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
WinSet, TransColor, %CustomColor% 200
SetTimer, UpdateOSD, 250
updateGUI(AgroBarMainX1,AgroBarMainY1, gwidth, gheight)
}
UpdateOSD:
result := updateGUI(AgroBarMainX1,AgroBarMainY1, gwidth, gheight)
RandSleep(50,60)
updateGUI(x, y, width, height){
Static pic, started := False
snap := Gdip_BitmapFromScreen(x "|" y "|" width "|" height)
hbitmap := Gdip_CreateHBITMAPFromBitmap(snap), image := "HBITMAP:*" hbitmap
If started
GuiControl,, pic, %image%
Else {
Gui, Add, Picture, Y++250 w75 h-1 vpic, %image%
started := True
Gui, Show
}
}
RandSleep(x,y) {
Random, rand, %x%, %y%
Sleep %rand%
}
Re: Search Image & Show it elsewhere
Since you removed Return from UpdateOSD, you might get some unexpected effects. Nonetheless, these rapid-cycle "magnifier" kinds of programs tend to require a lot of PC resources, as you are repeatedly capturing and processing a large amount of data.
I did not mean that you can remove Return from a subroutine. You can remove it from a function if it is the last command and is not returning anything. Some people still leave it there for consistency or readability.
I did not mean that you can remove Return from a subroutine. You can remove it from a function if it is the last command and is not returning anything. Some people still leave it there for consistency or readability.
Re: Search Image & Show it elsewhere
Makes sense. Thank you!
Who is online
Users browsing this forum: No registered users and 228 guests