public void DrawImageClipped(Gdi::Graphics g, Gdi::RectangleF clip) { clip.Intersect(imageArea); float cacheX = clip.X + 0.5f; if (offsetX > 0) { cacheX -= offsetX; } float cacheY = clip.Y + 0.5f; if (offsetY > 0) { cacheY -= offsetY; } #if WIN32PINVOKE using (Gdi::Graphics gImg = Gdi::Graphics.FromImage(this.cache)){ const int SRCCOPY = 0x00CC0020; System.IntPtr dstDC = g.GetHdc(); System.IntPtr srcDC = GetCacheHdc(dstDC); BitBlt( dstDC, (int)clip.X, (int)clip.Y, (int)clip.Width, (int)clip.Height, srcDC, (int)cacheX, (int)cacheY, SRCCOPY ); g.ReleaseHdc(dstDC); } #else Gdi::RectangleF rectI = new Gdi::RectangleF(cacheX, cacheY, clip.Width, clip.Height); g.DrawImage(this.cache, clip, rectI, Gdi::GraphicsUnit.Pixel); #endif }
/// <summary> /// /// </summary> /// <param name="g"> /// 作成元の Graphics を指定します。 /// 元の Graphics を操作する前に必ずこのインスタンスの Dispose を呼び出して下さい。 /// </param> public DeviceContext(Gdi::Graphics g) { this.hdc = g.GetHdc(); this.dispose = new System.Action <HDC>(g.ReleaseHdc); }