123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Drawing;
- using System.Reflection;
- namespace Microsoft.Drawing
- {
-
-
-
- public static class BufferedGraphicsEx
- {
- private static readonly FieldInfo FiTargetLoc;
- private static readonly FieldInfo FiVirtulSize;
-
-
-
- static BufferedGraphicsEx()
- {
- Type type = typeof(BufferedGraphics);
- BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
- FiTargetLoc = type.GetField("targetLoc", flags);
- FiVirtulSize = type.GetField("virtualSize", flags);
- }
-
-
-
-
-
- public static Point GetTargetLoc(BufferedGraphics bg)
- {
- if (bg == null)
- throw new ArgumentNullException("bg");
- return (Point)FiTargetLoc.GetValue(bg);
- }
-
-
-
-
-
- public static Size GetVirtualSize(BufferedGraphics bg)
- {
- if (bg == null)
- throw new ArgumentNullException("bg");
- return (Size)FiVirtulSize.GetValue(bg);
- }
-
-
-
-
-
-
- public static void Render(BufferedGraphics bgSrc, Graphics gDest, Rectangle rcDest)
- {
-
- if (bgSrc == null || gDest == null || !RectangleEx.IsVisible(rcDest))
- return;
-
- Point targetLoc = (Point)FiTargetLoc.GetValue(bgSrc);
- targetLoc.Offset(rcDest.X, rcDest.Y);
- Size virtualSize = rcDest.Size;
- Point sourceLoc = rcDest.Location;
-
- GraphicsEx.Render(bgSrc.Graphics, gDest, targetLoc, sourceLoc, virtualSize);
- }
-
-
-
-
-
- public static void BlendRender(BufferedGraphics bgSrc, Graphics gDest)
- {
-
- if (bgSrc == null || gDest == null)
- return;
-
- Point targetLoc = (Point)FiTargetLoc.GetValue(bgSrc);
- Size virtualSize = (Size)FiVirtulSize.GetValue(bgSrc);
-
- GraphicsEx.BlendRender(bgSrc.Graphics, gDest, targetLoc, Point.Empty, virtualSize);
- }
-
-
-
-
-
-
- public static void BlendRender(BufferedGraphics bgSrc, Graphics gDest, Rectangle rcDest)
- {
-
- if (bgSrc == null || gDest == null || !RectangleEx.IsVisible(rcDest))
- return;
-
- Point targetLoc = (Point)FiTargetLoc.GetValue(bgSrc);
- targetLoc.Offset(rcDest.X, rcDest.Y);
- Size virtualSize = rcDest.Size;
- Point sourceLoc = rcDest.Location;
-
- GraphicsEx.BlendRender(bgSrc.Graphics, gDest, targetLoc, sourceLoc, virtualSize);
- }
- }
- }
|