Results 1 to 6 of 6

Thread: [2.0] Help speeding up pixel color code [resolved]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Resolved [2.0] Help speeding up pixel color code [resolved]

    Code:
    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;
            }
    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. Thanks
    Last edited by cx323; Jun 12th, 2006 at 06:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width