Example #1
0
        // ###############################################################################
        // ### M E T H O D S
        // ###############################################################################

        #region Methods

        /// <summary>Get the image as System.Drawing.Bitmap.</summary>
        /// <returns>The image as bitmap on success, or null otherwise.<see cref="System.Drawing.Bitmap"/></returns>
        public System.Drawing.Bitmap GetBitmap()
        {
            if (_imageSurface == null || _imageSurface.Drawable == IntPtr.Zero)
            {
                return(null);
            }

            IntPtr image = X11lib.XGetImage(_imageSurface.Display, _imageSurface.Drawable,
                                            0, 0, (X11.TUint)_size.Width, (X11.TUint)_size.Height,
                                            (X11.TUlong)(UInt32.MaxValue), (X11.TInt) 2);

            if (image == IntPtr.Zero)
            {
                return(null);
            }

            System.Drawing.Bitmap bmp   = new System.Drawing.Bitmap(_size.Width, _size.Height);
            System.Drawing.Color  color = System.Drawing.Color.Black;
            for (int scanLine = 0; scanLine < _size.Height; scanLine++)
            {
                for (int scanCol = 0; scanCol < _size.Width; scanCol++)
                {
                    X11.TPixel pixel = X11lib.XGetPixel(image, (X11.TInt)scanCol, (X11.TInt)scanLine);
                    if (_imageSurface.Depth >= 24)
                    {
                        color = System.Drawing.Color.FromArgb((int)pixel);
                    }
                    else
                    {
                        color = System.Drawing.Color.FromArgb(_imageSurface.RgbForColor(pixel));
                    }
                    bmp.SetPixel(scanCol, scanLine, color);
                }
            }

            X11lib.XDestroyImage(image);
            return(bmp);
        }