示例#1
0
        public unsafe Bitmap Paint(byte[,,] data)
        {
            int width  = data.GetLength(1);
            int height = data.GetLength(0);

            Bitmap     Image      = new Bitmap(width, height);
            BitmapData bitmapData = Image.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                PixelFormat.Format32bppArgb
                );
            ColorARGB *startingPosition = (ColorARGB *)bitmapData.Scan0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    ColorARGB *position = startingPosition + j + i * width;
                    position->A = 255;
                    position->R = data[i, j, 0];
                    position->G = data[i, j, 1];
                    position->B = data[i, j, 2];
                }
            }

            Image.UnlockBits(bitmapData);
            internalBitmap = Image;
            return(Image);
        }
示例#2
0
        private unsafe Bitmap ToBitmap(double[,] rawImage)
        {
            int width  = rawImage.GetLength(1);
            int height = rawImage.GetLength(0);

            Bitmap     Image      = new Bitmap(width, height);
            BitmapData bitmapData = Image.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                PixelFormat.Format32bppArgb
                );
            ColorARGB *startingPosition = (ColorARGB *)bitmapData.Scan0;


            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    double color = rawImage[i, j];
                    byte   rgb   = (byte)(color * 255);

                    ColorARGB *position = startingPosition + j + i * width;
                    position->A = 255;
                    position->R = rgb;
                    position->G = rgb;
                    position->B = rgb;
                }
            }

            Image.UnlockBits(bitmapData);
            return(Image);
        }
示例#3
0
 public unsafe ColorARGB(ColorARGB *original, ColorARGB *alpha)
 {
     this.A = alpha->R;
     this.R = original->R;
     this.G = original->G;
     this.B = original->B;
 }
示例#4
0
        public unsafe Bitmap GetBitmap(ref Bitmap bitmap)
        {
            //bitmap = new Bitmap(EnvInfo.Width, EnvInfo.Height, PixelFormat.Format32bppPArgb);
            if (bitmap == null)
            {
                return(null);
            }

            Bitmap     Image      = new Bitmap(EnvInfo.Width, EnvInfo.Height);
            BitmapData bitmapData = Image.LockBits(
                new Rectangle(0, 0, EnvInfo.Width, EnvInfo.Height),
                ImageLockMode.ReadWrite,
                PixelFormat.Format32bppArgb
                );
            ColorARGB *startingPosition = (ColorARGB *)bitmapData.Scan0;


            for (int i = 0; i < EnvInfo.Width; i++)
            {
                for (int j = 0; j < EnvInfo.Height; j++)
                {
                    double color = Map[j, i];
                    byte   rgb   = (byte)(color * 255);

                    ColorARGB *position = startingPosition + j + i * EnvInfo.Width;
                    position->A = 255;
                    position->R = (byte)(255 - rgb);
                    position->G = (byte)(255 - rgb);
                    position->B = (byte)(255 - rgb);
                }
            }

            Image.UnlockBits(bitmapData);
            return(Image);
        }
示例#5
0
 public unsafe ColorARGB(ColorARGB *original)
 {
     this.A = 255;
     this.R = original->R;
     this.G = original->G;
     this.B = original->B;
 }
示例#6
0
        public static unsafe Bitmap ToBitmap(bool[] pixels, int width, int height)
        {
            Bitmap     Image      = new Bitmap(width, height);
            BitmapData bitmapData = Image.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                PixelFormat.Format32bppArgb
                );
            ColorARGB *startingPosition = (ColorARGB *)bitmapData.Scan0;


            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    ColorARGB *position = startingPosition + i + j * width;
                    position->A = 255;
                    position->R = 0;
                    position->G = 0;
                    position->B = pixels[(i * height) + j] ? (byte)255 : (byte)0;
                }
            }

            Image.UnlockBits(bitmapData);
            return(Image);
        }
示例#7
0
        /// <summary>
        /// Based on discussion at http://stackoverflow.com/questions/13511661/create-bitmap-from-double-two-dimentional-array
        /// and at https://code.google.com/p/renderterrain/source/browse/trunk/Utilities/FastBitmap.cs?r=18
        /// </summary>
        /// <param name="rawData">Integer array represents image ARGB</param>
        /// <returns>Bitmap from raw color data</returns>
        protected internal unsafe Bitmap ToBitmap(int[,] rawData)
        {
            int        width      = rawData.GetLength(0);
            int        height     = rawData.GetLength(1);
            Bitmap     img        = new Bitmap(width, height);
            BitmapData bitmapData = img.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
                );

            ColorARGB *startingPosition = (ColorARGB *)bitmapData.Scan0;


            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int        color    = rawData[j, i];
                    ColorARGB *position = startingPosition + j + i * width;
                    *          position = new ColorARGB(color);
                }
            }

            img.UnlockBits(bitmapData);

            return(img);
        }
示例#8
0
        protected internal unsafe Bitmap ComputeAlpha(Bitmap source, out Bitmap alpha)
        {
            int width  = source.Width;
            int height = source.Height;

            alpha = new Bitmap(width, height);
            Bitmap img = new Bitmap(width, height);

            BitmapData imgBitmapData = img.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb
                );
            BitmapData alphaBitmapData = alpha.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
                );

            BitmapData sourceBitmapData = source.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
                );

            ColorRGB * imgStartingPosition    = (ColorRGB *)imgBitmapData.Scan0;
            ColorARGB *sourceStartingPosition = (ColorARGB *)sourceBitmapData.Scan0;
            ColorARGB *alphaStartingPosition  = (ColorARGB *)alphaBitmapData.Scan0;


            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    ColorARGB *sourcePosition = sourceStartingPosition + j + i * width;
                    ColorARGB *alphaPosition  = alphaStartingPosition + j + i * width;
                    ColorRGB * imgPosition    = imgStartingPosition + j + i * width;
                    *          imgPosition    = new ColorRGB(sourcePosition);
                    *          alphaPosition  = new ColorARGB(255, sourcePosition->A, sourcePosition->A, sourcePosition->A);
                }
            }
            try
            {
                img.UnlockBits(imgBitmapData);
                alpha.UnlockBits(alphaBitmapData);
                source.UnlockBits(sourceBitmapData);
                return(img);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(new Bitmap(new MemoryStream(this.rawData)));
            }
        }
        private unsafe bool FindEyes(out EyeData leftEye, out EyeData rightEye)
        {
            const byte DifferenceThreshold = 25;

            int[,] changeCount = new int[workerImageArray[0].Width, workerImageArray[0].Height];

            for (int i = 0; i < workerImageArray.Length - 1; ++i)
            {
                FastBitmap differenceImage = workerImageArray[i].GetDifferenceImage(workerImageArray[i + 1], DifferenceThreshold);
                FastBitmap erosionImage    = differenceImage.ApplyCrossErosionMask();

                ColorARGB *currentPosition = erosionImage.StartingPosition;
                for (int y = 0; y < erosionImage.Height; ++y)
                {
                    for (int x = 0; x < erosionImage.Width; ++x)
                    {
                        if (currentPosition->B == 255)
                        {
                            ++changeCount[x, y];
                        }
                        ++currentPosition;
                    }
                }
                differenceImage.Dispose();
                erosionImage.Dispose();
            }

            FastBitmap finalDifferenceImage = new FastBitmap(workerImageArray[0].Width, workerImageArray[0].Height);

            ColorARGB *currentPositionResult = finalDifferenceImage.StartingPosition;

            for (int y = 0; y < finalDifferenceImage.Height; ++y)
            {
                for (int x = 0; x < finalDifferenceImage.Width; ++x)
                {
                    byte color = 0;

                    if (changeCount[x, y] > 0)
                    {
                        color = 255;
                    }

                    currentPositionResult->A = 255;
                    currentPositionResult->R = color;
                    currentPositionResult->G = color;
                    currentPositionResult->B = color;

                    ++currentPositionResult;
                }
            }

            return(FindEyesFromDifferenceImage(workerImageArray[workerImageArray.Length - 1], finalDifferenceImage, out leftEye, out rightEye));
        }
示例#10
0
        protected internal unsafe Bitmap UpdateAlpha(Bitmap source, Bitmap alpha)
        {
            int    width  = source.Width;
            int    height = source.Height;
            Bitmap img    = new Bitmap(width, height);

            BitmapData imgBitmapData = img.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
                );

            BitmapData sourceBitmapData = source.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadWrite,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
                );

            BitmapData alphaBitmapData = alpha.LockBits(
                new Rectangle(0, 0, width, height),
                ImageLockMode.ReadOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb
                );

            ColorARGB *imgStartingPosition    = (ColorARGB *)imgBitmapData.Scan0;
            ColorARGB *sourceStartingPosition = (ColorARGB *)sourceBitmapData.Scan0;
            ColorARGB *alphaStartingPosition  = (ColorARGB *)alphaBitmapData.Scan0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    ColorARGB *sourcePosition = sourceStartingPosition + j + i * width;
                    ColorARGB *alphaPosition  = alphaStartingPosition + j + i * width;
                    ColorARGB *imgPosition    = imgStartingPosition + j + i * width;
                    *          imgPosition    = new ColorARGB(sourcePosition, alphaPosition);
                }
            }

            img.UnlockBits(imgBitmapData);
            return(img);
        }
示例#11
0
 public unsafe void UpdateAlha(ColorARGB *alpha)
 {
     this.A = alpha->R;
 }