コード例 #1
0
ファイル: NativeMethods.cs プロジェクト: McoreD/ShareX.Wpf
 public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, System.Drawing.CopyPixelOperation dwRop);
コード例 #2
0
 public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, System.Drawing.CopyPixelOperation rop);
コード例 #3
0
        public static System.Drawing.Bitmap CopyFromScreenX11(int sourceX, int sourceY,
                                                              System.Drawing.Size blockRegionSize
                                                              , System.Drawing.CopyPixelOperation copyPixelOperation)
        {
            System.UIntPtr window;
            System.IntPtr  image, defvisual, vPtr;
            int            AllPlanes = ~0, nitems = 0, pixel;

            System.UIntPtr AllPlanes2 = new System.UIntPtr((uint)AllPlanes);


            if (copyPixelOperation != System.Drawing.CopyPixelOperation.SourceCopy)
            {
                throw new System.NotImplementedException("Operation not implemented under X11");
            }

            if (Gdip.Display == System.IntPtr.Zero)
            {
                Gdip.Display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero);
            }

            window    = LibX11Functions.XRootWindow(Gdip.Display, 0);
            defvisual = LibX11Functions.XDefaultVisual(Gdip.Display, 0);
            XVisualInfo visual = new XVisualInfo();

            // Get XVisualInfo for this visual
            visual.visualid = LibX11Functions.XVisualIDFromVisual(defvisual);
            vPtr            = LibX11Functions.XGetVisualInfo(Gdip.Display, VisualIDMask, ref visual, ref nitems);
            visual          = (XVisualInfo)System.Runtime.InteropServices.Marshal.PtrToStructure(vPtr, typeof(XVisualInfo));
            image           = LibX11Functions.XGetImage(Gdip.Display, window, sourceX, sourceY, (uint)blockRegionSize.Width,
                                                        (uint)blockRegionSize.Height, AllPlanes2, ZPixmap);
            if (image == System.IntPtr.Zero)
            {
                string s = string.Format("XGetImage returned NULL when asked to for a {0}x{1} region block",
                                         blockRegionSize.Width, blockRegionSize.Height);
                throw new System.InvalidOperationException(s);
            }

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(blockRegionSize.Width, blockRegionSize.Height);
            int red, blue, green;
            int red_mask = (int)visual.red_mask;
            int blue_mask  = (int)visual.blue_mask;
            int green_mask = (int)visual.green_mask;

            for (int y = 0; y < blockRegionSize.Height; y++)
            {
                for (int x = 0; x < blockRegionSize.Width; x++)
                {
                    pixel = LibX11Functions.XGetPixel(image, x, y);

                    switch (visual.depth)
                    {
                    case 16:     /* 16bbp pixel transformation */
                        red   = (int)((pixel & red_mask) >> 8) & 0xff;
                        green = (int)(((pixel & green_mask) >> 3)) & 0xff;
                        blue  = (int)((pixel & blue_mask) << 3) & 0xff;
                        break;

                    case 24:
                    case 32:
                        // int a = (int)((pixel ) >> 24) & 0xff;
                        red   = (int)((pixel & red_mask) >> 16) & 0xff;
                        green = (int)(((pixel & green_mask) >> 8)) & 0xff;
                        blue  = (int)((pixel & blue_mask)) & 0xff;
                        break;

                    default:
                        string text = string.Format("{0}bbp depth not supported.", visual.depth);
                        throw new System.NotImplementedException(text);
                    }

                    bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(255, red, green, blue));
                }
            }

            // DrawImage(bmp, destinationX, destinationY);
            // bmp.Dispose();
            LibX11Functions.XDestroyImage(image);
            LibX11Functions.XFree(vPtr);

            return(bmp);
        }