Helper Class that gets and sets image pixels using Marshal calls.
        /// <summary>
        /// Extracts image pixels into byte array "pixels".
        /// </summary>
        private void GetImagePixels()
        {
            //Performance upgrade, now encoding takes half of the time, due to Marshal calls.
            int count      = 0;
            var tempBitmap = new Bitmap(_image);

            var pixelUtil = new PixelUtil(tempBitmap);

            pixelUtil.LockBits();

            //Benchmark.Start();
            _pixels = new Byte[3 * _image.Width * _image.Height];

            for (int th = 0; th < _image.Height; th++)
            {
                for (int tw = 0; tw < _image.Width; tw++)
                {
                    Color color = pixelUtil.GetPixel(tw, th);
                    //_pixels[count] = color.R;
                    //count++;
                    //_pixels[count] = color.G;
                    //count++;
                    //_pixels[count] = color.B;
                    //count++;

                    _pixels[count] = color.B;
                    count++;
                    _pixels[count] = color.G;
                    count++;
                    _pixels[count] = color.R;
                    count++;
                }
            }

            pixelUtil.UnlockBits();

            //Benchmark.End();
            //Console.WriteLine(Benchmark.GetSeconds
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extracts image pixels into byte array "pixels".
        /// </summary>
        private void GetImagePixels()
        {
            //Performance upgrade, now encoding takes half of the time, due to Marshal calls.
            var count      = 0;
            var tempBitmap = new Bitmap(_image);

            var pixelUtil = new PixelUtil(tempBitmap);

            pixelUtil.LockBits();

            _colorList = new List <Color>();
            _pixels    = new byte[3 * _image.Width * _image.Height];

            for (var th = 0; th < _image.Height; th++)
            {
                for (var tw = 0; tw < _image.Width; tw++)
                {
                    var color = pixelUtil.GetPixel(tw, th);
                    //_pixels[count] = color.R;
                    //count++;
                    //_pixels[count] = color.G;
                    //count++;
                    //_pixels[count] = color.B;
                    //count++;

                    _colorList.Add(color);

                    _pixels[count] = color.B;
                    count++;
                    _pixels[count] = color.G;
                    count++;
                    _pixels[count] = color.R;
                    count++;
                }
            }

            pixelUtil.UnlockBits();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Extracts image pixels into byte array "pixels".
        /// </summary>
        private void GetImagePixels()
        {
            //Performance upgrade, now encoding takes half of the time, due to Marshal calls.
            int count = 0;
            var tempBitmap = new Bitmap(_image);

            var pixelUtil = new PixelUtil(tempBitmap);
            pixelUtil.LockBits();

            //Benchmark.Start();
            _pixels = new Byte[3 * _image.Width * _image.Height];

            for (int th = 0; th < _image.Height; th++)
            {
                for (int tw = 0; tw < _image.Width; tw++)
                {
                    Color color = pixelUtil.GetPixel(tw, th);
                    //_pixels[count] = color.R;
                    //count++;
                    //_pixels[count] = color.G;
                    //count++;
                    //_pixels[count] = color.B;
                    //count++;

                    _pixels[count] = color.B;
                    count++;
                    _pixels[count] = color.G;
                    count++;
                    _pixels[count] = color.R;
                    count++;
                }
            }

            pixelUtil.UnlockBits();

            //Benchmark.End();
            //Console.WriteLine(Benchmark.GetSeconds
        }
Ejemplo n.º 4
0
        private void SetPixels(int[] pixels)
        {
            var image = new PixelUtil(_bitmap);
            image.LockBits();

            int count = 0;
            for (int th = 0; th < _image.Height; th++)
            {
                for (int tw = 0; tw < _image.Width; tw++)
                {
                    Color color = Color.FromArgb(pixels[count++]);
                    image.SetPixel(tw, th, color);
                }
            }

            image.UnlockBits();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates new frame image from current data (and previous frames as specified by their disposition codes).
        /// </summary>
        /// <param name="bitmap">The bitmap to get the pixels.</param>
        /// <returns>The pixel array.</returns>
        private int[] GetPixels(Bitmap bitmap)
        {
            int[] pixels = new int[3 * _image.Width * _image.Height];
            int count = 0;

            var image = new PixelUtil(bitmap);
            image.LockBits();

            for (int th = 0; th < _image.Height; th++)
            {
                for (int tw = 0; tw < _image.Width; tw++)
                {
                    Color color = image.GetPixel(tw, th);
                    pixels[count] = color.R;
                    count++;
                    pixels[count] = color.G;
                    count++;
                    pixels[count] = color.B;
                    count++;
                }
            }

            image.UnlockBits();
            
            return pixels;
        }