SoFunction
Updated on 2025-03-06

Read a specific example of image pixels


   public static short[][] GetPixs(Bitmap bitmap)
        {
            int height = ;
            int width = ;
            byte tempB, tempG, tempR;
            short[][] spOriginData = new short[height][];
            for (int i = 0; i < height; i++)
            {
                spOriginData[i] = new short[width];
            }

            BitmapData dataOut = (new Rectangle(0, 0, width, height), , PixelFormat.Format24bppRgb);
            int offset = - * 3;
            try
            {
                unsafe
                {
                    byte* pOut = (byte*)(dataOut.());

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            tempB = pOut[0];
                            tempG = pOut[1];
                            tempR = pOut[2];
                            double data=0.31 * tempR + 0.59 * tempG + 0.11 * tempB;
                            if (data > 255)
                                spOriginData[y][x] = 255;
                            else
                                if (data < 0)
                                    spOriginData[y][x] = 0;
                                else
                                    spOriginData[y][x] = (short)data;
                            pOut += 3;
                        }
                        pOut += offset;
                    }
                    (dataOut);
                }
            }
            catch
            {
            }
            return spOriginData;
        }