Exemplo n.º 1
0
        public MemImage(Image img)
            : this(img.Width, img.Height)
        {
            using (UnsafeBitmap bmp = new UnsafeBitmap(img))
            {
                bmp.LockBitmap();

                Parallel.For(0, Height, j =>
                {
                    //for (int j = 0; j < Height; j++)
                    //{

                    for (int i = 0; i < Width; i++)
                    {
                        PixelData pixelInput = bmp.GetPixel(i, j);
                        array[i][j] = pixelInput;
                    }
                    //}
                });
                bmp.UnlockBitmap();
            }
        }
Exemplo n.º 2
0
        public Image ToImage()
        {
            Bitmap bmp = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            int iWidth = Width;
            int iHeight = Height;
            UnsafeBitmap output = new UnsafeBitmap(iWidth, iHeight);
            output.LockBitmap();

            for (int j = 0; j < iHeight; j++)
            //   Parallel.For(0, iHeight, j =>
            {

                for (int i = 0; i < iWidth; i++)
                {
                    PixelData pixelInput = array[i][j];
                    output.SetPixel(i, j, pixelInput);
                }
                //});
            }

            output.UnlockBitmap();
            return output.Bitmap;

            //for (int j = 0; j < Height; j++)
            //{
            //    for (int i = 0; i < Width; i++)
            //    {
            //        bmp.SetPixel(i, j, array[i, j].ToColor());
            //    }
            //}
            //return bmp;
        }