The code above is a function to find the x and y coordinates of a dark pixel. It works fine, but it's really slow, it take around 150ms on a 220x180 pixel image. In vb6 i was able to use dma and it took less than a ms, so i assume there's a better way. If someone could tell me what way would be faster that would be great. ThanksCode:public static string OIR(string strPicPath) { int y = 0; int x = 0; DateTime tmStart = DateTime.Now; Bitmap b = new Bitmap(strPicPath); BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int stride = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; unsafe { byte* p = (byte*)(void*)Scan0; int nOffset = stride - b.Width * 3; byte red, green, blue; for (y = 0; y < b.Height; y++) { for (x = 0; x < b.Width; x++) { blue = p[0]; green = p[1]; red = p[2]; if (blue < 40 && green < 90 && red < 80) { DateTime tmEnd = DateTime.Now; TimeSpan tmDiff = tmEnd - tmStart; //MessageBox.Show ("blue: " + blue + "green: " + "red: " + red); MessageBox.Show("x: " + x + "y: " + y); MessageBox.Show(tmDiff.TotalMilliseconds.ToString()); return "&x=" + x + "&y=" + y; } p += 3; } p += nOffset; } } return "&x=" + x + "&y=" + y; }




Reply With Quote