/*
##############################################
ImageSearch 연습 10 gui
- 목표
window에 image를 보여주고, 찾기 버튼으로 찾도록한다.
###############################################
*/
#SingleInstance, Force ;이 스크립트는 동시에 한개만 실행되도록 한다. 이미 동작중이면 kill 하고 다시 실행한다.
#noenv ;변수가 window 환경변수값인지 체크하지 않는다. 속도 향상
SetBatchLines, -1 ;라인간 딜레이 없음. 속도향상
ListLines, off ;최근실행한 line을 보여주지 않도록한다. 속도향상, 간혹 디버깅시 불편할수 있음.
;#include Gdip.ahk ;lib 폴더에 있으면 주석 처리 가능.
SetWorkingDir, %A_ScriptDir% ;스크립트가 있는 폴더를 실행폴더로 설정합니다.
;image파일 이름만 있는경우, 현재 실행 폴더에서 이미지 파일을 찾습니다.
;winset,TransColor,eeaaff
Gui, 1:Add, Text,section , image1.jpg
Gui, 1:Add, button, ggGui1 vvGuiB_find,찾아라
Gui, 1:Add, Text,, image1.bmp
Gui, 1:Add, Picture, ,image1.bmp
Gui, 1:Add, Text,, image1.jpg
Gui, 1:Add, Picture,x+0 yp ,image1.jpg
Gui, 1:Add, Text,xs, image1.png
Gui, 1:Add, Picture,x+0 yp,image1.png
Gui, 1:show, w250
return
gGui1:
if(A_GuiControl=="vGuiB_find")
gosub L_findImage
return
; ImageSearch 수행하는 lable
L_findImage:
coordmode pixel,screen ; imageSearch시 좌표는 전체 화면에서의 좌표.
coordmode tooltip,screen ; tooltip 을 보여줄때 좌표는 전체 화면에서의 좌표
startX=0
starty=0
endX:=A_ScreenWidth
endY:=A_ScreenHeight
File_Image1 = image1.jpg
FoundImageCount=0
f_getImageSize( A_ScriptDir "\" File_Image1,image_w,image_h) ; 전달하는 이미지파일의 가로 세로 크기를 얻어온다.
sx:=startX
sy:=starty
ex:=endX
ey:=endY
state=0 ; 발견하면 1로 설정하고,
; 1 이면 오른쪽 남은 부분 검색
; 1 일때 검색 실패하면, 0 으로 변경하고 그 아래줄 왼쪽처음부터 검색
; tx,ty에서 발견시 두부분 추가 검색
; 1. ( tx+1,ty)~ (ex,ty) ; 오른쪽 한줄만 검색
; 0. (0,ty+1)~(ex,ey); ; 그다음줄은 첨부터 다시 검색
loop
{
; 좌표값을 변경하기위해서 변수 sx,sy,ex,ey로 좌표값 표현.
ImageSearch, foundX,foundY,%sx%,%sy%,%ex%,%eY%,%File_Image1%
if errorlevel = 0
{
tooltip,%A_Index% [x:%foundX%] [y:%foundY%] 찾았다.!!,foundX,foundY
msgbox %A_Index% 찾았다!!! [x:%foundX%] [y:%foundY%] tooltip 보세요.
FoundImageCount++
; 이미지 찾았을 경우 다음 시작위치를 찾은 위치 오른쪽 부터 이미지 사이즈 만큼 높이로 설정
; state를 1로 변경, 다시 찾기 수행하도록함.
sx:=foundx+1
sy:=foundy
ey:=foundy+image_h
state:=1
continue
}
else if ErrorLevel = 2
{
MsgBox imageSearch를 수행 할 수 없습니다.
break
}
else if ErrorLevel = 1
{
if(state == 1) ; 오른쪽 찾기 state에서 이미지를 못 찾았음. 다음줄 왼쪽 처음부터 찾기 시작하도록 좌표 설정, state 0으로 변경
{
sx := startX
sy := sy+1
ey := endy
state := 0
continue
}
MsgBox %FoundImageCount% 개의 이미지를 찾았습니다.
break
}
}
return
guiclose:
exitapp
f_getImageSize(imagefile="", Byref width=0,Byref height=0){
GDIPToken := Gdip_Startup()
pBM := Gdip_CreateBitmapFromFile( imagefile )
Width:= Gdip_GetImageWidth( pBM )
height:= Gdip_GetImageHeight( pBM )
Gdip_DisposeImage( pBM )
Gdip_Shutdown( GDIPToken )
}
'Autohotkey > AutoHotKey강좌' 카테고리의 다른 글
11 autohotkey gui control 위치 조절 (0) | 2016.06.10 |
---|---|
예제 9, gui button , guicontrol (0) | 2016.06.03 |
예제 8 Gui Button (0) | 2016.06.02 |