레이블이 Image인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Image인 게시물을 표시합니다. 모든 게시물 표시

2016. 3. 11.

이미지파일 첨부안하고 스크립트안에 포함시키기

[출처:http://autohotkey.co.kr/b/6-172] ImMBR님 공유스크립트


http://www.autohotkey.com/forum/topic10957.html
http://www.autohotkey.com/forum/topic29199.html

별도의 외부 이미지 파일 없이 스크립트 안에 이미지를 포함시키는 방법입니다.

1. 이미지파일 변환
오직 BMP 포맷만 지원합니다.
다음 스크립트를 실행시키고 가장 위의 Edit창에 변환할 bmp파일의 이름을 적고 Open File 버튼을 눌러줍니다.
밑의 Edit 창에 16진수로 변환된 이미지 파일의 내용이 나타납니다.
전체를 복사해서 텍스트 파일로 저장해 두세요.

gui, add, edit, w400 vFile,
gui, add, button, w100 gOpen x+10,Open File
gui, add, edit, r40 w510 vOutput xm
gui, show
Open:
gui, submit, nohide
BinRead(file,data)
Bin2Hex(h,data,res)
guicontrol,,output,%h%
return
Bin2Hex(ByRef h, ByRef b, n=0)      ; n bytes binary data -> stream of 2-digit hex
{                                   ; n = 0: all (SetCapacity can be larger than used!)
   format = %A_FormatInteger%       ; save original integer format
   SetFormat Integer, Hex           ; for converting bytes to hex
   m := VarSetCapacity(b)
   If (n < 1 or n > m)
       n := m
   Address := &b
   h =
   Loop %n%
   {
      x := *Address                 ; get byte in hex
      StringTrimLeft x, x, 2        ; remove 0x
      x = 0%x%                      ; pad left
      StringRight x, x, 2           ; 2 hex digits
      h = %h%%x%
      Address++
   }
   SetFormat Integer, %format%      ; restore original format
}
BinRead(file, ByRef data, n=0, offset=0)
{
   h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
   IfEqual h,-1, SetEnv, ErrorLevel, -1
   IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file
   m = 0                            ; seek to offset
   IfLess offset,0, SetEnv,m,2
   r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
   IfEqual r,0, SetEnv, ErrorLevel, -3
   IfNotEqual ErrorLevel,0, {
      t = %ErrorLevel%              ; save ErrorLevel to be returned
      DllCall("CloseHandle", "Uint", h)
      ErrorLevel = %t%              ; return seek error
      Return 0
   }
   m := DllCall("GetFileSize","UInt",h,"Int64 *",r)
   If (n < 1 or n > m)
       n := m
   Granted := VarSetCapacity(data, n, 0)
   IfLess Granted,%n%, {
      ErrorLevel = Mem=%Granted%
      Return 0
   }
   result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0)
   if (!result or Read < n)
       t = -3
   IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%
   h := DllCall("CloseHandle", "Uint", h)
   IfEqual h,-1, SetEnv, ErrorLevel, -2
   IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel%
   Return Read
}



2. 다음 스크립트의 ~~~부분에 위에서 구한 16진수 데이터를 적당한 크기로 나눠서 넣어주시면 끝~
LoadBitmap1:
BMPH =
(
;~~~~~~~~~~~~~~~~~
)
BMPH =%BMPH%
(
;~~~~~~~~~~~~~~~~~
)

다음은 제가 직접 만들어서 확인한 예제입니다.

Gui 1:+LastFound
GUI1:=WinExist() , hDC:=DllCall("GetDC",UInt,Gui1)
Gui, Add, Text, w32 h32 0xE hwndhPic ; SS_BITMAP = 0xE
GoSub, LoadBitmap1
hBMP := DllCall( "CreateDIBitmap", UInt,hDC, UInt,(bmiHAddr:=&BMP+14)
       ,UInt,(CBM_INIT:=4), UInt,&BMP+NumGet(BMP,10), UInt,&BMP+14, UInt,(DIB_PAL_COLORS:=1) )      
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP,, ahk_id %hPic%
Gui, Show, w160 h120, sample
Return
GuiClose:
GuiEscape:
ExitApp
Return
LoadBitmap1:
BMPH =
(
424d360c000000000000360000002800000020000000200000000100180000000000000c000012170000121700000000000000000000ffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffffffffff000000ffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff000000ffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000ffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff33ccff000000ffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffffffffffffffffffffff00000000000033ccff33ccff33ccff33ccff33ccff000000ffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffffffffff00000000000033ccff33ccff33ccff33ccff000000000000000000000000000000ffff
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff33ccff33ccff33ccff0000006699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff0000006699cc000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffff
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff0000006699cc0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff00000033ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000000000000000033ccff33ccff33ccff33ccff33ccff33ccff0000000000000000006699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000000000033ccff33ccff
)
BMPH =%BMPH%
(
33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000033ccff33ccff00000033ccff33ccff33ccff00000000000000000000000033ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff00000000000033ccff33ccff33ccff000000ffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff00000033ccff33ccff33ccff000000ffffffffffff000000ffffffffffffffffff000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffff000000ffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffff000000ffffff0000
)
BMPH =%BMPH%
(
00ffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffff000000ffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000000000000000000000000000ffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffff00000033ccff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000000000000000033ccff33ccff33ccff33ccff33ccff33ccff000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000ffffffffffff000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000ffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)


; Laszlo's MCode() ; http://www.autohotkey.com/forum/viewtopic.php?p=135302#135302
nSize := StrLen(BMPH)//2
VarSetCapacity( BMP,nSize )
Loop % nSize
  NumPut( "0x" . SubStr(BMPH,2*A_Index-1,2), BMP, A_Index-1, "Char" )
BMPH= ; empty it
Return

2016. 2. 26.

Print Screen(캡쳐) 누르면 bmp자동저장 & 그림판 실행

스크립트에 대한 설명:


개인적으로 요긴하게 사용하고 있어서 함 올려봅니다.
키보드상의 Print Screen (화면캡쳐) 키 실행시 바탕화면에 '해당시각.bmp' 파일로 이미지를 저장하고,
그림판으로 해당 파일을 open 해주는 스크립트 입니다.


출처 : www.autohotkey.com/forum/viewtopic.php?t=35242







; By SKAN    www.autohotkey.com/forum/viewtopic.php?t=35242
ClipboardGet_DIB()
{
 If DllCall("IsClipboardFormatAvailable", UInt,2 )
   DllCall( "OpenClipboard", UInt,0 ), tBM := DllCall("GetClipboardData", UInt,2 )
 , hBM := DllCall( "CopyImage", UInt,tBM, UInt,0, Int,0,Int,0, UInt,0x2000, UInt )
 , DllCall( "CloseClipboard" )

 Return hBM ? hBM : 0
}


; By SKAN    www.autohotkey.com/forum/viewtopic.php?t=35242
GDI_SaveBitmap( hBM, File )

 DllCall( "GetObject", Int,hBM, Int,VarSetCapacity($,84), UInt,NumPut(0,$,40,"Short")-42 )
 Numput( VarSetCapacity(BFH,14,0)+40, Numput((NumGet($,44)+54),Numput(0x4D42,BFH)-2)+4 )
 If ( hF := DllCall( "CreateFile", Str,File,UInt,2**30,UInt,2,Int,0,UInt,2,Int64,0 ) ) > 0
   DllCall( "WriteFile", UInt,hF, UInt,&BFH,  UInt,14, IntP,0,Int,0 ) ; BITMAPFILEHEADER
 , DllCall( "WriteFile", UInt,hF, UInt,&$+24, UInt,40, IntP,0,Int,0 ) ; BITMAPINFOHEADER
 , DllCall( "WriteFile", UInt,hF, UInt,NumGet($,20), UInt,NumGet($,44), UIntP,BW, Int,0 )
 , DllCall( "CloseHandle", UInt,hF )

 Return BW ? 54+BW : 0
}







~!PrintScreen::
 ~PrintScreen::
sleep, 50
current_time := substr(a_now, 1, 4) . " " . substr(a_now, 5, 2) . " " . substr(a_now, 7, 2) . " " . substr(a_now, 9, 6)
file_name1 :=  A_Desktop . "\" . current_time . ".bmp"

 If GDI_SaveBitmap( ClipboardGet_DIB(), OUTF := file_name1 ){
  Runwait, mspaint.exe "%file_name1%", file_name1
  }
return

2016. 2. 18.

멀티 이미지서치 함수 (동일한 이미지가 다수 존재할때 유용)

스크립트에 대한 설명:

동일한 이미지가 다수 존재하는 경우의 Imagesearch 함수입니다.
요새 질문으로 많이 올라오는 것 같아서...
알고리즘이 형편없어서 생각보다 시간이 많이 걸리는군요.
조금씩 손봐서 사용하셔야 될 듯 합니다;;;




^s::
SetBatchLines,-1
CoordMode,Pixel,Screen
CoordMode,ToolTip,Screen
result:=MultipleImagesearch(1,1,1024,768,"sample2.bmp")
Loop,Parse,result,`n
{
If A_LoopField=
Break
StringSplit,Pos,A_LoopField,a
ToolTip,%A_Index%,%Pos1%,%Pos2%,%A_Index%
}
return





MultipleImagesearch(xs,ys,xl,yl,image)
{
pos=
xss:=xs
yss:=ys
loop
{
Imagesearch,x,yi,%xss%,%yss%,%xl%,%yl%,%image%
If Errorlevel=1
Break
pos=%pos%%x%a%yi%`n
loop
{
xss:=x+1
If xss=%xl%
Break
Imagesearch,x,y,%xss%,%yss%,%xl%,%yl%,%image%
If Errorlevel=1
Break
pos=%pos%%x%a%y%`n
}
xss:=xs
yss:=yi+1
If yss=%yl%
Break
}
Sort,pos,u
return pos
}




ImageSearch 함수를 간편하게...


예를들면.. 페이지로딩확인, 버튼 클릭, 업로드 완료체크(이미지를 못찾을때까지)
Loop
{
   ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, 이미지
   If ErrorLevel = 0
   Break
}


이렇게 만들어보니.. 스크립트 절반이 이미지서치로 도배가 되더군요! ㅠ
지금은 좀더 공부해서 함수를 이용해서 사용하고있어요.
아래는 스크립트 내용입니다.

ISearch(ByRef x,ByRef y, img) {
   Loop {
      ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, %img%
      If ErrorLevel = 0
      Break
   } x += 10, y += 10   ;확실한 클릭을위해서 좌우로 10픽셀씩 내려줍니다 :)
   Return
}


여기까지 입니다^^
이렇게 만들어놓은 후 필요할때
ISearch(x, y, "이미지")

이렇게 함수를 불러와 적용하니 스크립트 내용이 절반가량이 줄게되었어요~
사용하는 경우에 따라서 좀더 응용해봅니다.. :)
이미지를 못찾을경우도 포함하고싶다면..

ISearch(bln, ByRef x,ByRef y, img) {
   Loop {
      ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, %img%
      If ErrorLevel = %bln%
      Break
   } x += 10, y += 10
   Return
}

필요할때마다 불러와줍니다~

ISearch("0혹은1", x, y, "이미지")

이런식으로 필요에따라 수정해서 사용하시면 될것 같아요 ^^




[출처 : http://autohotkey.co.kr/b/1-425 만약에님 공유스크립트]