Browse image's pixel

Hi,

I have to get the value of each pixel of an image to do some comparaison. I used the class Bitmap and i loaded a 800x600 image. It takes me 20s to browse all pixel. (i used the method getpixel in a double for statement) I want to know if there is a class, or an other method to do this faster (around 1s would be perfect)

Thanks

David



Answer this question

Browse image's pixel

  • Matt Stum

    I am doing this in J#!!! Is it possible anyway
  • cristi_bd

    Hi Davemord

    Use the following, I think it will be much faster.

    "
    int width = bmp.Width;
    int height = bmp.Height;

    int[] buffer = new int[width * height];

    BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

    Marshal.Copy(bmpData.Scan0, buffer, 0, buffer.Length);

    "

    Then you use bmpData to access the pixel-data of your image.
    For instance:

    int x = 10;
    int y = 20;
    if(bmpData[y*width + x] == Color.Green.ToArgb()) {
    // Do something
    }


    Kind Regards

  • Moopy

    Unfortunately J# doesn’t support unsafe code on its own... is there any chance that you could build a C# class (in a separate assembly) to do the unsafe work you need and then access it from your J# code

  • ProxyPro

    Not very! It's an option, but we will try to find something else before doing this.
  • SCRunner

    If you are doing this C# you could try a little Unsafe Image Processing.

  • Browse image's pixel