[C#] 이미지서치 – autohotkey dll use

using System.Runtime.InteropServices;

[DllImport("ImageSearchDLL.dll")]
private static extern IntPtr ImageSearch(int x, int y, int right, int bottom, [MarshalAs(UnmanagedType.LPStr)]string imagePath);

string[] search = UseImageSearch("*30 img\\img.png");

//UseImageSearch("*오차값 이미지파일.png"); 로 오토핫키에서의 사용법과 동일합니다.

if (search == null)

return;                   //서치실패의 경우 return

int[] search_ = new int[search.Length];

for (int j = 0; j < search.Length; j++)
{
   search_[j] = Convert.ToInt32(search[j]);
}

MessageBox.Show(search_[1]+","+search_[2]);

//함수부분. 물론 함수를 사용하지않고 다이렉트로 해도 상관없음.

public static String[] UseImageSearch(string imgPath)
{
            int right = Screen.PrimaryScreen.WorkingArea.Right;
            int bottom = Screen.PrimaryScreen.WorkingArea.Bottom;

            IntPtr result = ImageSearch(0, 0, right, bottom, imgPath);
            String res = Marshal.PtrToStringAnsi(result);

//이미지 서치 결과값  0번 =  결과 성공1 실패0 1,2번 = x,y 3,4번 = 이미지의 세로가로길이

//res = 한자씩 나눠져있음

          

            if (res[0] == '0') //res를 이용하여 이미지여부 확인
            {
                MessageBox.Show("Not found");
                return null;
            }

            String[] data = res.Split('|'); // |로 결과 값을 조각
            int x; int y;
            int.TryParse(data[1], out x); //x좌표
            int.TryParse(data[2], out y); //y좌표

            //for(int i=0; i<5; i++)
            //  MessageBox.Show(i + "번째 " + data[i]);

            return data;
        }

 

[첨부파일]

ImageSearchDLL.zip

Post Author: 김 키티

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다