gasilrf.blogg.se

Get mouse coordinates windows
Get mouse coordinates windows




get mouse coordinates windows

Rectangle rect = FindImageOnScreen(ImgToFind, false) Private void Form2_Load(object sender, EventArgs e)

get mouse coordinates windows

Private Bitmap ScreenBmp = new image screen.png") Private Bitmap ImgToFind = new image.png") Here is the result of the new example and the images I used. That way we all use the same thing and no mouse etc. Int skpx = 32((bmpMatch.Width - 1) / (double)10) Įdit: To keep it simple here is a new simplified example using your images and it just gives the found image rectangle result. Marshal.Copy(ScreenBmd.Scan0, ScreenByts, 0, ScreenByts.Length) Marshal.Copy(ImgBmd.Scan0, ImgByts, 0, ImgByts.Length) G.CopyFromScreen(, Point.Empty,, CopyPixelOperation.SourceCopy) īitmapData ImgBmd = bmpMatch.LockBits(new Rectangle(0, 0, bmpMatch.Width, bmpMatch.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb) īitmapData ScreenBmd = ScreenBmp.LockBits(, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb) īyte ImgByts = new byte īyte ScreenByts = new byte Using (Graphics g = Graphics.FromImage(ScreenBmp)) Private static Rectangle FindImageOnScreen(Bitmap bmpMatch, bool ExactMatch)īitmap ScreenBmp = new Bitmap(,, PixelFormat.Format24bppRgb) Point cntr = new Point(rect.X, rect.Y) Point cntr = new Point(rect.X + 32(rect.Width / (double)2), rect.Y + 32(rect.Height / (double)2)) Rectangle rect = FindImageOnScreen(ImgToFind1, true) Ĭonsole.WriteLine( + " " + ) I have converted that image pixel from 32bpp to 24bpp.īitmap ImgToFind = new ImgToFind1 = new Bitmap(ImgToFind.Width, ImgToFind.Height, PixelFormat.Format24bppRgb) Always return the incorrect x,y coordinates( and ) if find the image on the screen, so cursor moved to different location.

Get mouse coordinates windows code#

I have converted that VB.net code into C# code here But sometime failed to find the image on the screen.






Get mouse coordinates windows