1

i have a black/white line-sensor wich gives me the grayscale values (0-255) of scanned data. i want to save this values as Bitmap (.bmp) and also show them in a picturebox. my current code looks like this:

        PixelFormat px = PixelFormat.Canonical;
        Bitmap bitmap = new Bitmap(width, height, px);
        int[,] GreyScaleArray2D = new int[width,height];

        for (int yy = 0; yy < (lb_SpReceivedData.Count-width); yy += width)
        {
            for (int xx = 0; xx < width; xx++)
            {
                GreyScaleArray2D[xx,tmp] = lb_SpReceivedData[(yy+xx)];
            }
            tmp++;
        }

        for (int y = 0; y < height; y++)
        {
           for (int x = 0; x < width; x++)
           {
              int red = GreyScaleArray2D[x,y]; // read from array
              int green = GreyScaleArray2D[x,y]; // read from array
              int blue = GreyScaleArray2D[x,y]; // read from array
              bitmap.SetPixel(x, y, Color.FromArgb(0, red, green, blue));
           }
        }

        pictureBox1.Image = bitmap; 
  1. Question) i get an error of invalid parameter if i pass

         PixelFormat.Canonical
    

    to the bitmap constructor.

  2. Question) even though i pass the bitmap to my picturebox there is nothing to see in the picturebox! what am i doing wrong?

thanks

arash javanmard
  • 1,168
  • 2
  • 14
  • 33

0 Answers0