Ejemplo n.º 1
0
        public Bitmap CopyFromScreen(int sourceX, int sourceY, Size blockRegionSize,
                                     CopyPixelOperation copyPixelOperation, PixelFormat pixelFormat)
        {
            var bmp = new Bitmap(blockRegionSize.Width, blockRegionSize.Height, pixelFormat);

            Graphics.FromImage(bmp).CopyFromScreen(sourceX, sourceY, 0, 0, new Size(blockRegionSize.Width, blockRegionSize.Width), copyPixelOperation);

            return(bmp);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Performs a bit-block transfer of color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics.
 /// </summary>
 /// <param name="g"></param>
 /// <param name="upperLeftSource">The point at the upper-left corner of the source rectangle.</param>
 /// <param name="upperLeftDestination">The point at the upper-left corner of the destination rectangle.</param>
 /// <param name="blockRegionSize">The size of the area to be transferred</param>
 /// <param name="copyPixelOperation">One of the <see cref="CopyPixelOperation"/> values.</param>
 public static void CopyFromScreen(
     this Graphics g,
     Point upperLeftSource,
     Point upperLeftDestination,
     Size blockRegionSize,
     CopyPixelOperation copyPixelOperation)
 {
     CopyFromScreen(g, upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y, blockRegionSize, copyPixelOperation);
 }
Ejemplo n.º 3
0
        public Bitmap CopyFromScreen(int sourceX, int sourceY, Size blockRegionSize, CopyPixelOperation copyPixelOperation,
                                     PixelFormat pixelFormat)
        {
            var bmp = new Bitmap(blockRegionSize.Width, blockRegionSize.Height);
            var g   = Graphics.FromImage(bmp);

            g.DrawImage(_currentImage, 0, 0, new Rectangle(sourceX, sourceY, blockRegionSize.Width, blockRegionSize.Height), GraphicsUnit.Pixel);

            return(bmp);
        }
Ejemplo n.º 4
0
 internal static extern bool BitBlt(
     IntPtr destinationDcHandle,
     int destinationX,
     int destinationY,
     int width,
     int height,
     IntPtr sourceDcHandle,
     int sourceX,
     int sourceY,
     CopyPixelOperation rasterOperation);
Ejemplo n.º 5
0
 internal static extern bool BitBlt(
     IntPtr destinationDcHandle,
     int destinationX,
     int destinationY,
     int width,
     int height,
     IntPtr sourceDcHandle,
     int sourceX,
     int sourceY,
     CopyPixelOperation rasterOperation);
Ejemplo n.º 6
0
 private static extern int BitBlt(
     IntPtr hdcDest,          // handle to destination DC目标设备的句柄
     int nXDest,              // x-coord of destination upper-left corner目标对象的左上角的X坐标
     int nYDest,              // y-coord of destination upper-left corner目标对象的左上角的Y坐标
     int nWidth,              // width of destination rectangle目标对象的矩形宽度
     int nHeight,             // height of destination rectangle目标对象的矩形长度
     IntPtr hdcSrc,           // handle to source DC源设备的句柄
     int nXSrc,               // x-coordinate of source upper-left corner源对象的左上角的X坐标
     int nYSrc,               // y-coordinate of source upper-left corner源对象的左上角的Y坐标
     CopyPixelOperation dwRop // raster operation code光栅的操作值
     );
Ejemplo n.º 7
0
        public Bitmap CopyFromScreen(int sourceX, int sourceY, Size blockRegionSize, CopyPixelOperation copyPixelOperation,
                                     PixelFormat pixelFormat)
        {
            var bmp = new Bitmap(blockRegionSize.Width, blockRegionSize.Height, pixelFormat);

            using (var grD = Graphics.FromImage(bmp))
            {
                grD.DrawImage(_image, new Rectangle(0, 0, blockRegionSize.Width, blockRegionSize.Height), new Rectangle(sourceX, sourceY, blockRegionSize.Width, blockRegionSize.Height), GraphicsUnit.Pixel);
            }

            return(bmp);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="sourceX">The x-coordinate of the point at the upper-left corner of the source rectangle.</param>
        /// <param name="sourceY">The y-coordinate of the point at the upper-left corner of the source rectangle</param>
        /// <param name="destinationX">The x-coordinate of the point at the upper-left corner of the destination rectangle.</param>
        /// <param name="destinationY">The y-coordinate of the point at the upper-left corner of the destination rectangle.</param>
        /// <param name="blockRegionSize">The size of the area to be transferred.</param>
        /// <param name="copyPixelOperation">One of the <see cref="CopyPixelOperation"/> values.</param>
        /// <remarks>The CopyFromScreen methods are useful for layering one image on top of another.
        /// The copyPixelOperation parameter allows you to specify if and how the source colors should be blended with the colors in the destination area.</remarks>
        public static void CopyFromScreen(
            this Graphics g,
            int sourceX,
            int sourceY,
            int destinationX,
            int destinationY,
            Size blockRegionSize,
            CopyPixelOperation copyPixelOperation)
        {
            IntPtr screenHdc = NativeMethods.GdiGetWindowDC(IntPtr.Zero);
            IntPtr hdc       = g.GetHdc();
            bool   success   = NativeMethods.GdiBitBlt(hdc, destinationX, destinationY, blockRegionSize.Width, blockRegionSize.Height, screenHdc, sourceX, sourceY, copyPixelOperation);

            NativeMethods.GdiReleaseDC(IntPtr.Zero, screenHdc);
            g.ReleaseHdc(hdc);
        }
Ejemplo n.º 9
0
        /// <summary>Creates a new <see cref="T:System.Drawing.Analysis.SlowBitmapPixelProvider"/> instance using a screenshot of a spefic rectangle on the screen.</summary>
        /// <param name="rectangle">The rectangle</param>
        /// <param name="operation">The <see cref="T:System.Drawing.CopyPixelOperation"/> to use.</param>
        /// <returns>A new <see cref="T:System.Drawing.Analysis.SlowBitmapPixelProvider"/> instance.</returns>
        public static SlowBitmapPixelProvider FromScreen(Rectangle rectangle, CopyPixelOperation operation)
        {
            if (rectangle.Width < 1)
                throw new ArgumentException("The width must not be 0 or less.");
            if (rectangle.Height < 1)
                throw new ArgumentException("The height must not be 0 or less.");

            using (var bmp = new Bitmap(rectangle.Width, rectangle.Height))
            {
                using (var g = Graphics.FromImage(bmp))
                {
                    g.Clear(GdiConstants.CopyFromScreenBugFixColor.ToDrawingColor());
                    g.CopyFromScreen(rectangle.X, rectangle.Y, 0, 0, bmp.Size, operation);
                    return new SlowBitmapPixelProvider(bmp.Clone() as Bitmap, true);
                }
            }
        }
Ejemplo n.º 10
0
        public static Bitmap Capture(Rectangle area)
        {
            IntPtr desktopHandle   = NativeMethods.GetDesktopWindow();
            IntPtr desktopDC       = NativeMethods.GetWindowDC(desktopHandle);
            IntPtr destinationDC   = NativeMethods.CreateCompatibleDC(desktopDC);
            IntPtr bitmapHandle    = NativeMethods.CreateCompatibleBitmap(desktopDC, area.Width, area.Height);
            IntPtr oldBitmapHandle = NativeMethods.SelectObject(destinationDC, bitmapHandle);

            const CopyPixelOperation operation = CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt;

            NativeMethods.BitBlt(destinationDC, 0, 0, area.Width, area.Height, desktopDC, area.X, area.Y, operation);

            Bitmap desktopCapture = Image.FromHbitmap(bitmapHandle);

            NativeMethods.SelectObject(destinationDC, oldBitmapHandle);
            NativeMethods.DeleteObject(bitmapHandle);
            NativeMethods.DeleteDC(destinationDC);
            NativeMethods.ReleaseDC(desktopHandle, desktopDC);

            return(desktopCapture);
        }
Ejemplo n.º 11
0
        public static Bitmap Get(int x, int y, int w, int h)
        {
            Bitmap screenshot = new Bitmap(
                w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            using (Graphics screenGraph = Graphics.FromImage(screenshot))
            {
                //
                Point upperLeftSource                 = new Point(x, y);
                Point upperLeftDestination            = new Point(0, 0);
                Size  blockRegionSize                 = new Size(w, h);
                CopyPixelOperation copyPixelOperation = CopyPixelOperation.SourceCopy;


                screenGraph.CopyFromScreen(
                    upperLeftSource,
                    upperLeftDestination,
                    blockRegionSize,
                    copyPixelOperation);
            }

            return(screenshot);
        }
Ejemplo n.º 12
0
 private static extern bool StretchBlt(SafeHandle hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, SafeHandle hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, CopyPixelOperation dwRop);
Ejemplo n.º 13
0
 public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     throw new NotImplementedException();
 }
	public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) {}
Ejemplo n.º 15
0
 internal void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize,
     CopyPixelOperation copyPixelOperation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int
                           wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);
Ejemplo n.º 17
0
 public static extern bool StretchBlt(SafeHandle hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, SafeHandle hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, CopyPixelOperation dwRop);
Ejemplo n.º 18
0
 public abstract void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation);
Ejemplo n.º 19
0
 public abstract void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation);
Ejemplo n.º 20
0
        internal static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,
			int nWidthDest, int nHeightDest,
			IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
			CopyPixelOperation dwRop);
Ejemplo n.º 21
0
 public extern static bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int wDst, int hDst, IntPtr hdcSrc, int xSrc, int ySrc, CopyPixelOperation op);
 public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     switch (copyPixelOperation)
     {
         case CopyPixelOperation.NotSourceErase:
         case CopyPixelOperation.NotSourceCopy:
         case CopyPixelOperation.NoMirrorBitmap:
         case CopyPixelOperation.Blackness:
         case CopyPixelOperation.SourceErase:
         case CopyPixelOperation.DestinationInvert:
         case CopyPixelOperation.PatInvert:
         case CopyPixelOperation.SourceInvert:
         case CopyPixelOperation.MergeCopy:
         case CopyPixelOperation.SourceCopy:
         case CopyPixelOperation.SourceAnd:
         case CopyPixelOperation.MergePaint:
         case CopyPixelOperation.SourcePaint:
         case CopyPixelOperation.PatCopy:
         case CopyPixelOperation.PatPaint:
         case CopyPixelOperation.Whiteness:
         case CopyPixelOperation.CaptureBlt:
         {
             new UIPermission(UIPermissionWindow.AllWindows).Demand();
             int width = blockRegionSize.Width;
             int height = blockRegionSize.Height;
             using (DeviceContext context = DeviceContext.FromHwnd(IntPtr.Zero))
             {
                 HandleRef hSrcDC = new HandleRef(null, context.Hdc);
                 HandleRef hDC = new HandleRef(null, this.GetHdc());
                 try
                 {
                     if (SafeNativeMethods.BitBlt(hDC, destinationX, destinationY, width, height, hSrcDC, sourceX, sourceY, (int) copyPixelOperation) == 0)
                     {
                         throw new Win32Exception();
                     }
                 }
                 finally
                 {
                     this.ReleaseHdc();
                 }
             }
             return;
         }
     }
     throw new InvalidEnumArgumentException("value", (int) copyPixelOperation, typeof(CopyPixelOperation));
 }
 public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     this.CopyFromScreen(upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y, blockRegionSize, copyPixelOperation);
 }
 public static extern bool BitBlt(IntPtr handle, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr handleObjectSource, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
Ejemplo n.º 25
0
 public static extern bool BitBlt(IntPtr destinationDeviceContext, int destinationXAxis, int destinationYAxis,
                                  int destinationWidth, int destinationHeight, IntPtr sourceDeviceContext, int sourceXAxis, int sourceYAxis,
                                  CopyPixelOperation rasterOperationCode);
Ejemplo n.º 26
0
		public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
		{
			if (!Enum.IsDefined (typeof (CopyPixelOperation), copyPixelOperation))
				throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for CopyPixelOperation", copyPixelOperation));

			if (GDIPlus.UseX11Drawable) {
				CopyFromScreenX11 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
			} else if (GDIPlus.UseCarbonDrawable) {
				CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
			} else if (GDIPlus.UseCocoaDrawable) {
				CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
			} else {
				CopyFromScreenWin32 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
			}
		}
Ejemplo n.º 27
0
 public static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop); //TernaryRasterOperations
Ejemplo n.º 28
0
		private void CopyFromScreenWin32 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
		{
			IntPtr window = GDIPlus.GetDesktopWindow ();
			IntPtr srcDC = GDIPlus.GetDC (window);
			IntPtr dstDC = GetHdc ();
			GDIPlus.BitBlt (dstDC, destinationX, destinationY, blockRegionSize.Width,
				blockRegionSize.Height, srcDC, sourceX, sourceY, (int) copyPixelOperation);

			GDIPlus.ReleaseDC (IntPtr.Zero, srcDC);
			ReleaseHdc (dstDC);			
		}
Ejemplo n.º 29
0
 public static extern bool BitBlt(IntPtr hDestDC, int X, int Y, int nWidth, int nHeight, IntPtr hSrcDC, int SrcX, int SrcY, CopyPixelOperation Rop);
Ejemplo n.º 30
0
		private void CopyFromScreenX11 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
		{
			IntPtr window, image, defvisual, vPtr;
			int AllPlanes = ~0, nitems = 0, pixel;

			if (copyPixelOperation != CopyPixelOperation.SourceCopy)
				throw new NotImplementedException ("Operation not implemented under X11");
		
			if (GDIPlus.Display == IntPtr.Zero) {
				GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
			}

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

			/* Get XVisualInfo for this visual */
			visual.visualid = GDIPlus.XVisualIDFromVisual(defvisual);
			vPtr = GDIPlus.XGetVisualInfo (GDIPlus.Display, 0x1 /* VisualIDMask */, ref visual, ref nitems);
			visual = (XVisualInfo) Marshal.PtrToStructure(vPtr, typeof (XVisualInfo));
#if false
			Console.WriteLine ("visual\t{0}", visual.visual);
			Console.WriteLine ("visualid\t{0}", visual.visualid);
			Console.WriteLine ("screen\t{0}", visual.screen);
			Console.WriteLine ("depth\t{0}", visual.depth);
			Console.WriteLine ("klass\t{0}", visual.klass);
			Console.WriteLine ("red_mask\t{0:X}", visual.red_mask);
			Console.WriteLine ("green_mask\t{0:X}", visual.green_mask);
			Console.WriteLine ("blue_mask\t{0:X}", visual.blue_mask);
			Console.WriteLine ("colormap_size\t{0}", visual.colormap_size);
			Console.WriteLine ("bits_per_rgb\t{0}", visual.bits_per_rgb);
#endif
			image = GDIPlus.XGetImage (GDIPlus.Display, window, sourceX, sourceY, blockRegionSize.Width,
				blockRegionSize.Height, AllPlanes, 2 /* ZPixmap*/);
			if (image == 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 InvalidOperationException (s);
			}
				
			Bitmap bmp = new 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 = GDIPlus.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:
							red = (int) ((pixel & red_mask ) >> 16) & 0xff;
							green = (int) (((pixel & green_mask ) >> 8 )) & 0xff;
							blue = (int) ((pixel & blue_mask )) & 0xff;
							break;
						default:
							string text = Locale.GetText ("{0}bbp depth not supported.", visual.depth);
							throw new NotImplementedException (text);
					}
						
					bmp.SetPixel (x, y, Color.FromArgb (255, red, green, blue));							 
				}
			}

			DrawImage (bmp, destinationX, destinationY);
			bmp.Dispose ();
			GDIPlus.XDestroyImage (image);
			GDIPlus.XFree (vPtr);
		}
Ejemplo n.º 31
0
 public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Bitblt extension for the graphics object
 /// </summary>
 /// <param name="target"></param>
 /// <param name="source"></param>
 public static void BitBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Point destination, CopyPixelOperation rop)
 {
     using (SafeDeviceContextHandle targetDC = target.getSafeDeviceContext())
     {
         using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC))
         {
             using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap()))
             {
                 using (SafeSelectObjectHandle selectObject = safeCompatibleDCHandle.SelectObject(hBitmapHandle))
                 {
                     BitBlt(targetDC, destination.X, destination.Y, source.Width, source.Height, safeCompatibleDCHandle, source.Left, source.Top, rop);
                 }
             }
         }
     }
 }
	public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation) {}
Ejemplo n.º 34
0
 public static extern bool BitBlt(SafeHandle hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, SafeHandle hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
Ejemplo n.º 35
0
 public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 36
0
 public static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop); //TernaryRasterOperations
Ejemplo n.º 37
0
 public static extern bool BitBlt(SafeHandle hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, SafeHandle hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
Ejemplo n.º 38
0
 internal static extern bool BitBlt(IntPtr hdcDst, int x1, int y1, int cx, int cy, IntPtr hdcSrc, int x2, int y2, CopyPixelOperation op);
Ejemplo n.º 39
0
 /// <summary>
 /// Bitblt extension for the graphics object
 /// </summary>
 /// <param name="target"></param>
 /// <param name="source"></param>
 public static void BitBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Point destination, CopyPixelOperation rop)
 {
     using (SafeDeviceContextHandle targetDC = target.GetSafeDeviceContext())
     {
         using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC))
         {
             using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap()))
             {
                 using (safeCompatibleDCHandle.SelectObject(hBitmapHandle))
                 {
                     BitBlt(targetDC, destination.X, destination.Y, source.Width, source.Height, safeCompatibleDCHandle, source.Left, source.Top, rop);
                 }
             }
         }
     }
 }
Ejemplo n.º 40
0
 public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
                                  int nWidth, int nHeight, IntPtr hObjectSource,
                                  int nXSrc, int nYSrc, CopyPixelOperation rop);
Ejemplo n.º 41
0
 public static extern bool BitBlt(IntPtr hDestDC, int X, int Y, int nWidth, int nHeight, IntPtr hSrcDC, int SrcX, int SrcY, CopyPixelOperation Rop);
Ejemplo n.º 42
0
 public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     this.baseGraphics.CopyFromScreen(sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
 }
Ejemplo n.º 43
0
 public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
Ejemplo n.º 44
0
        // roughly the same code as in Graphics.cs
        internal static void CopyPixels(IntPtr sourceHwnd, IDeviceContext targetDC, Point sourceLocation, Point destinationLocation, Size blockRegionSize, CopyPixelOperation copyPixelOperation) {
            int destWidth = blockRegionSize.Width;
            int destHeight = blockRegionSize.Height;

            DeviceContext dc = DeviceContext.FromHwnd(sourceHwnd);
            HandleRef targetHDC = new HandleRef( null, targetDC.GetHdc());
            HandleRef screenHDC = new HandleRef( null, dc.Hdc );
            
            try {
                bool result = SafeNativeMethods.BitBlt(targetHDC, destinationLocation.X, destinationLocation.Y, destWidth, destHeight, 
                                                      screenHDC,
                                                      sourceLocation.X, sourceLocation.Y, (int) copyPixelOperation);
                
                //a zero result indicates a win32 exception has been thrown
                if (!result) {
                    throw new Win32Exception();
                }
            }
            finally {
                targetDC.ReleaseHdc();
                dc.Dispose();
            }
        }
Ejemplo n.º 45
0
 internal static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
Ejemplo n.º 46
0
        /// <summary>
        /// Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the GraphicsEx.
        /// </summary>
        /// <param name="sourceX">The x-coordinate of the point at the upper-left corner of the source rectangle.</param>
        /// <param name="sourceY">The y-coordinate of the point at the upper-left corner of the source rectangle</param>
        /// <param name="destinationX">The x-coordinate of the point at the upper-left corner of the destination rectangle.</param>
        /// <param name="destinationY">The y-coordinate of the point at the upper-left corner of the destination rectangle.</param>
        /// <param name="blockRegionSize">The size of the area to be transferred.</param>
        /// <param name="copyPixelOperation">One of the <c>CopyPixelOperation</c> values.</param>
        public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
        {
            IntPtr desktopHwnd = GetDesktopWindow();

            if (desktopHwnd == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }
            IntPtr desktopDC = GetWindowDC(desktopHwnd);

            if (desktopDC == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }
            if (!BitBlt(hDC, destinationX, destinationY, blockRegionSize.Width, blockRegionSize.Height, desktopDC, sourceX, sourceY, copyPixelOperation))
            {
                throw new System.ComponentModel.Win32Exception();
            }
            ReleaseDC(desktopHwnd, desktopDC);
        }
Ejemplo n.º 47
0
 static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, CopyPixelOperation rop);
 static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,
                               int nWidthDest, int nHeightDest,
                               IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
                               CopyPixelOperation dwRop);
Ejemplo n.º 49
0
 public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
Ejemplo n.º 50
0
        public static void CopyFromScreen(this Graphics g, int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
        {
            IntPtr desktopWindow = Win32.GetDesktopWindow();

            if (desktopWindow == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }
            IntPtr windowDC = Win32.GetWindowDC(desktopWindow);

            if (windowDC == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }

            IntPtr hDC = g.GetHdc();

            if (!Win32.BitBlt(
                    hDC, destinationX, destinationY, blockRegionSize.Width, blockRegionSize.Height, windowDC, sourceX, sourceY, copyPixelOperation))
            {
                throw new System.ComponentModel.Win32Exception();
            }
            Win32.ReleaseDC(desktopWindow, windowDC);
        }
Ejemplo n.º 51
0
 public void CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     this.baseGraphics.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize, copyPixelOperation);
 }
Ejemplo n.º 52
0
 public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     this.baseGraphics.CopyFromScreen(sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
 }
 internal static void CopyPixels(IntPtr sourceHwnd, IDeviceContext targetDC, Point sourceLocation, Point destinationLocation, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
 {
     int width = blockRegionSize.Width;
     int height = blockRegionSize.Height;
     DeviceContext context = DeviceContext.FromHwnd(sourceHwnd);
     HandleRef hDC = new HandleRef(null, targetDC.GetHdc());
     HandleRef hSrcDC = new HandleRef(null, context.Hdc);
     try
     {
         if (!System.Windows.Forms.SafeNativeMethods.BitBlt(hDC, destinationLocation.X, destinationLocation.Y, width, height, hSrcDC, sourceLocation.X, sourceLocation.Y, (int) copyPixelOperation))
         {
             throw new Win32Exception();
         }
     }
     finally
     {
         targetDC.ReleaseHdc();
         context.Dispose();
     }
 }
Ejemplo n.º 54
0
        public void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) {
            
            switch(copyPixelOperation) { 
                case CopyPixelOperation.Blackness:
                case CopyPixelOperation.NotSourceErase:
                case CopyPixelOperation.NotSourceCopy:
                case CopyPixelOperation.SourceErase:
                case CopyPixelOperation.DestinationInvert:
                case CopyPixelOperation.PatInvert:
                case CopyPixelOperation.SourceInvert:
                case CopyPixelOperation.SourceAnd:
                case CopyPixelOperation.MergePaint:
                case CopyPixelOperation.MergeCopy:
                case CopyPixelOperation.SourceCopy:
                case CopyPixelOperation.SourcePaint:
                case CopyPixelOperation.PatCopy:
                case CopyPixelOperation.PatPaint:
                case CopyPixelOperation.Whiteness:
                case CopyPixelOperation.CaptureBlt:
                case CopyPixelOperation.NoMirrorBitmap:
                    break;
                default: 
                    throw new InvalidEnumArgumentException("value", unchecked((int)copyPixelOperation), typeof(CopyPixelOperation)); 
             }
            (new System.Security.Permissions.UIPermission(System.Security.Permissions.UIPermissionWindow.AllWindows)).Demand();
            
            int destWidth = blockRegionSize.Width;
            int destHeight = blockRegionSize.Height; 

            using( DeviceContext dc = DeviceContext.FromHwnd( IntPtr.Zero )){  // screen DC
                HandleRef screenDC = new HandleRef( null, dc.Hdc );
                HandleRef targetDC = new HandleRef( null, this.GetHdc());      // this DC

                try{
                    int result = SafeNativeMethods.BitBlt(targetDC, destinationX, destinationY, destWidth, destHeight, 
                                                          screenDC, sourceX, sourceY, unchecked((int) copyPixelOperation));
                
                    //a zero result indicates a win32 exception has been thrown
                    if (result == 0) {
                        throw new Win32Exception();
                    }
                }
                finally {
                    this.ReleaseHdc();
                }
            }
        }