2 // System.Drawing.Graphics.cs
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com) (stubbed out)
6 // Alexandre Pigolkine(pigolkine@gmx.de)
7 // Jordi Mas i Hernandez (jordi@ximian.com)
8 // Sebastien Pouliot <sebastien@ximian.com>
10 // Copyright (C) 2003 Ximian, Inc. (http://www.ximian.com)
11 // Copyright (C) 2004-2006 Novell, Inc. (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
35 using System.Drawing.Text;
36 using System.ComponentModel;
37 using System.Runtime.InteropServices;
38 using System.Security.Permissions;
41 namespace System.Drawing
46 public sealed class Graphics : MarshalByRefObject, IDisposable
51 internal IntPtr nativeObject = IntPtr.Zero;
52 internal CarbonContext context;
53 private bool disposed = false;
54 private static float defDpiX = 0;
55 private static float defDpiY = 0;
56 private IntPtr deviceContextHdc;
61 public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
65 PlayRecordCallback callbackData);
70 public delegate bool DrawImageAbort (IntPtr callbackData);
72 internal Graphics (IntPtr nativeGraphics)
74 nativeObject = nativeGraphics;
82 static internal float systemDpiX {
85 Bitmap bmp = new Bitmap (1, 1);
86 Graphics g = Graphics.FromImage (bmp);
94 static internal float systemDpiY {
97 Bitmap bmp = new Bitmap (1, 1);
98 Graphics g = Graphics.FromImage (bmp);
106 internal IntPtr NativeObject {
112 nativeObject = value;
116 [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
117 public void AddMetafileComment (byte [] data)
119 throw new NotImplementedException ();
122 public GraphicsContainer BeginContainer ()
126 status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
127 GDIPlus.CheckStatus (status);
129 return new GraphicsContainer(state);
132 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]
133 public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
137 status = GDIPlus.GdipBeginContainerI (nativeObject, ref dstrect, ref srcrect, unit, out state);
138 GDIPlus.CheckStatus (status);
140 return new GraphicsContainer (state);
143 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]
144 public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
148 status = GDIPlus.GdipBeginContainer (nativeObject, ref dstrect, ref srcrect, unit, out state);
149 GDIPlus.CheckStatus (status);
151 return new GraphicsContainer (state);
155 public void Clear (Color color)
158 status = GDIPlus.GdipGraphicsClear (nativeObject, color.ToArgb ());
159 GDIPlus.CheckStatus (status);
162 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
163 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
165 CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
166 blockRegionSize, CopyPixelOperation.SourceCopy);
169 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
170 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
172 CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
173 blockRegionSize, copyPixelOperation);
176 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
177 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize)
179 CopyFromScreen (sourceX, sourceY, destinationX, destinationY, blockRegionSize,
180 CopyPixelOperation.SourceCopy);
183 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
184 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
186 if (!Enum.IsDefined (typeof (CopyPixelOperation), copyPixelOperation))
187 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for CopyPixelOperation", copyPixelOperation));
189 if (GDIPlus.UseX11Drawable) {
190 CopyFromScreenX11 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
191 } else if (GDIPlus.UseCocoaDrawable || GDIPlus.UseQuartzDrawable) {
192 CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
194 CopyFromScreenWin32 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
198 private void CopyFromScreenWin32 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
200 IntPtr window = GDIPlus.GetDesktopWindow ();
201 IntPtr srcDC = GDIPlus.GetDC (window);
202 IntPtr dstDC = GetHdc ();
203 GDIPlus.BitBlt (dstDC, destinationX, destinationY, blockRegionSize.Width,
204 blockRegionSize.Height, srcDC, sourceX, sourceY, (int) copyPixelOperation);
206 GDIPlus.ReleaseDC (IntPtr.Zero, srcDC);
210 private void CopyFromScreenMac (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
212 throw new NotImplementedException ();
215 private void CopyFromScreenX11 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
217 IntPtr window, image, defvisual, vPtr;
218 int AllPlanes = ~0, nitems = 0, pixel;
220 if (copyPixelOperation != CopyPixelOperation.SourceCopy)
221 throw new NotImplementedException ("Operation not implemented under X11");
223 if (GDIPlus.Display == IntPtr.Zero) {
224 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
227 window = GDIPlus.XRootWindow (GDIPlus.Display, 0);
228 defvisual = GDIPlus.XDefaultVisual (GDIPlus.Display, 0);
229 XVisualInfo visual = new XVisualInfo ();
231 /* Get XVisualInfo for this visual */
232 visual.visualid = GDIPlus.XVisualIDFromVisual(defvisual);
233 vPtr = GDIPlus.XGetVisualInfo (GDIPlus.Display, 0x1 /* VisualIDMask */, ref visual, ref nitems);
234 visual = (XVisualInfo) Marshal.PtrToStructure(vPtr, typeof (XVisualInfo));
236 /* Sorry I do not have access to a computer with > deepth. Fell free to add more pixel formats */
237 image = GDIPlus.XGetImage (GDIPlus.Display, window, sourceX, sourceY, blockRegionSize.Width,
238 blockRegionSize.Height, AllPlanes, 2 /* ZPixmap*/);
240 Bitmap bmp = new Bitmap (blockRegionSize.Width, blockRegionSize.Height);
241 int red, blue, green;
242 for (int y = sourceY; y < sourceY + blockRegionSize.Height; y++) {
243 for (int x = sourceX; x < sourceX + blockRegionSize.Width; x++) {
244 pixel = GDIPlus.XGetPixel (image, x, y);
246 switch (visual.depth) {
247 case 16: /* 16bbp pixel transformation */
248 red = (int) ((pixel & visual.red_mask ) >> 8) & 0xff;
249 green = (int) (((pixel & visual.green_mask ) >> 3 )) & 0xff;
250 blue = (int) ((pixel & visual.blue_mask ) << 3 ) & 0xff;
254 red = (int) ((pixel & visual.red_mask ) >> 16) & 0xff;
255 green = (int) (((pixel & visual.green_mask ) >> 8 )) & 0xff;
256 blue = (int) ((pixel & visual.blue_mask )) & 0xff;
259 throw new NotImplementedException ("Deepth not supported right now");
262 bmp.SetPixel (x, y, Color.FromArgb (255, red, green, blue));
266 DrawImage (bmp, 0, 0);
268 GDIPlus.XDestroyImage (image);
269 GDIPlus.XFree (vPtr);
273 public void Dispose ()
277 status = GDIPlus.GdipDeleteGraphics (nativeObject);
278 nativeObject = IntPtr.Zero;
279 GDIPlus.CheckStatus (status);
280 if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero) {
281 Carbon.ReleaseContext (context.port, context.ctx);
286 GC.SuppressFinalize(this);
290 public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
292 DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
296 public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
298 DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
302 public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
306 throw new ArgumentNullException ("pen");
308 status = GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
309 x, y, width, height, startAngle, sweepAngle);
310 GDIPlus.CheckStatus (status);
313 // Microsoft documentation states that the signature for this member should be
314 // public void DrawArc( Pen pen, int x, int y, int width, int height, int startAngle,
315 // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
316 public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
320 throw new ArgumentNullException ("pen");
321 status = GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
322 x, y, width, height, startAngle, sweepAngle);
323 GDIPlus.CheckStatus (status);
326 public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
330 throw new ArgumentNullException ("pen");
331 status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
332 pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
333 pt3.Y, pt4.X, pt4.Y);
334 GDIPlus.CheckStatus (status);
337 public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
341 throw new ArgumentNullException ("pen");
342 status = GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject,
343 pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
344 pt3.Y, pt4.X, pt4.Y);
345 GDIPlus.CheckStatus (status);
348 public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
352 throw new ArgumentNullException ("pen");
353 status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1,
354 y1, x2, y2, x3, y3, x4, y4);
355 GDIPlus.CheckStatus (status);
358 public void DrawBeziers (Pen pen, Point [] points)
361 throw new ArgumentNullException ("pen");
363 throw new ArgumentNullException ("points");
365 int length = points.Length;
371 for (int i = 0; i < length - 1; i += 3) {
372 Point p1 = points [i];
373 Point p2 = points [i + 1];
374 Point p3 = points [i + 2];
375 Point p4 = points [i + 3];
377 status = GDIPlus.GdipDrawBezier (nativeObject,
379 p1.X, p1.Y, p2.X, p2.Y,
380 p3.X, p3.Y, p4.X, p4.Y);
381 GDIPlus.CheckStatus (status);
385 public void DrawBeziers (Pen pen, PointF [] points)
388 throw new ArgumentNullException ("pen");
390 throw new ArgumentNullException ("points");
392 int length = points.Length;
398 for (int i = 0; i < length - 1; i += 3) {
399 PointF p1 = points [i];
400 PointF p2 = points [i + 1];
401 PointF p3 = points [i + 2];
402 PointF p4 = points [i + 3];
404 status = GDIPlus.GdipDrawBezier (nativeObject,
406 p1.X, p1.Y, p2.X, p2.Y,
407 p3.X, p3.Y, p4.X, p4.Y);
408 GDIPlus.CheckStatus (status);
413 public void DrawClosedCurve (Pen pen, PointF [] points)
416 throw new ArgumentNullException ("pen");
418 throw new ArgumentNullException ("points");
421 status = GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
422 GDIPlus.CheckStatus (status);
425 public void DrawClosedCurve (Pen pen, Point [] points)
428 throw new ArgumentNullException ("pen");
430 throw new ArgumentNullException ("points");
433 status = GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);
434 GDIPlus.CheckStatus (status);
437 public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode)
440 throw new ArgumentNullException ("pen");
442 throw new ArgumentNullException ("points");
445 status = GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
446 GDIPlus.CheckStatus (status);
449 public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode)
452 throw new ArgumentNullException ("pen");
454 throw new ArgumentNullException ("points");
457 status = GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
458 GDIPlus.CheckStatus (status);
461 public void DrawCurve (Pen pen, Point [] points)
464 throw new ArgumentNullException ("pen");
466 throw new ArgumentNullException ("points");
469 status = GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);
470 GDIPlus.CheckStatus (status);
473 public void DrawCurve (Pen pen, PointF [] points)
476 throw new ArgumentNullException ("pen");
478 throw new ArgumentNullException ("points");
481 status = GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);
482 GDIPlus.CheckStatus (status);
485 public void DrawCurve (Pen pen, PointF [] points, float tension)
488 throw new ArgumentNullException ("pen");
490 throw new ArgumentNullException ("points");
493 status = GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
494 GDIPlus.CheckStatus (status);
497 public void DrawCurve (Pen pen, Point [] points, float tension)
500 throw new ArgumentNullException ("pen");
502 throw new ArgumentNullException ("points");
505 status = GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
506 GDIPlus.CheckStatus (status);
509 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
512 throw new ArgumentNullException ("pen");
514 throw new ArgumentNullException ("points");
517 status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
518 points, points.Length, offset,
519 numberOfSegments, 0.5f);
520 GDIPlus.CheckStatus (status);
523 public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension)
526 throw new ArgumentNullException ("pen");
528 throw new ArgumentNullException ("points");
531 status = GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject,
532 points, points.Length, offset,
533 numberOfSegments, tension);
534 GDIPlus.CheckStatus (status);
537 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
540 throw new ArgumentNullException ("pen");
542 throw new ArgumentNullException ("points");
545 status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
546 points, points.Length, offset,
547 numberOfSegments, tension);
548 GDIPlus.CheckStatus (status);
551 public void DrawEllipse (Pen pen, Rectangle rect)
554 throw new ArgumentNullException ("pen");
556 DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
559 public void DrawEllipse (Pen pen, RectangleF rect)
562 throw new ArgumentNullException ("pen");
563 DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
566 public void DrawEllipse (Pen pen, int x, int y, int width, int height)
569 throw new ArgumentNullException ("pen");
571 status = GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
572 GDIPlus.CheckStatus (status);
575 public void DrawEllipse (Pen pen, float x, float y, float width, float height)
578 throw new ArgumentNullException ("pen");
579 Status status = GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height);
580 GDIPlus.CheckStatus (status);
583 public void DrawIcon (Icon icon, Rectangle targetRect)
586 throw new ArgumentNullException ("icon");
588 DrawImage (icon.GetInternalBitmap (), targetRect);
591 public void DrawIcon (Icon icon, int x, int y)
594 throw new ArgumentNullException ("icon");
596 DrawImage (icon.GetInternalBitmap (), x, y);
599 public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
602 throw new ArgumentNullException ("icon");
604 DrawImageUnscaled (icon.GetInternalBitmap (), targetRect);
607 public void DrawImage (Image image, RectangleF rect)
610 throw new ArgumentNullException ("image");
612 Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y, rect.Width, rect.Height);
613 GDIPlus.CheckStatus (status);
616 public void DrawImage (Image image, PointF point)
619 throw new ArgumentNullException ("image");
621 Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);
622 GDIPlus.CheckStatus (status);
625 public void DrawImage (Image image, Point [] destPoints)
628 throw new ArgumentNullException ("image");
629 if (destPoints == null)
630 throw new ArgumentNullException ("destPoints");
632 Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
633 GDIPlus.CheckStatus (status);
636 public void DrawImage (Image image, Point point)
639 throw new ArgumentNullException ("image");
640 DrawImage (image, point.X, point.Y);
643 public void DrawImage (Image image, Rectangle rect)
646 throw new ArgumentNullException ("image");
647 DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
650 public void DrawImage (Image image, PointF [] destPoints)
653 throw new ArgumentNullException ("image");
654 if (destPoints == null)
655 throw new ArgumentNullException ("destPoints");
656 Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
657 GDIPlus.CheckStatus (status);
660 public void DrawImage (Image image, int x, int y)
663 throw new ArgumentNullException ("image");
664 Status status = GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
665 GDIPlus.CheckStatus (status);
668 public void DrawImage (Image image, float x, float y)
671 throw new ArgumentNullException ("image");
672 Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
673 GDIPlus.CheckStatus (status);
676 public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
679 throw new ArgumentNullException ("image");
680 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
681 destRect.X, destRect.Y, destRect.Width, destRect.Height,
682 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
683 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
684 GDIPlus.CheckStatus (status);
687 public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
690 throw new ArgumentNullException ("image");
691 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
692 destRect.X, destRect.Y, destRect.Width, destRect.Height,
693 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
694 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
695 GDIPlus.CheckStatus (status);
698 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
701 throw new ArgumentNullException ("image");
702 if (destPoints == null)
703 throw new ArgumentNullException ("destPoints");
705 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
706 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
707 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
709 GDIPlus.CheckStatus (status);
712 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
715 throw new ArgumentNullException ("image");
716 if (destPoints == null)
717 throw new ArgumentNullException ("destPoints");
719 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
720 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
721 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
723 GDIPlus.CheckStatus (status);
726 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit,
727 ImageAttributes imageAttr)
730 throw new ArgumentNullException ("image");
731 if (destPoints == null)
732 throw new ArgumentNullException ("destPoints");
733 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
734 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
735 srcRect.Width, srcRect.Height, srcUnit,
736 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
737 GDIPlus.CheckStatus (status);
740 public void DrawImage (Image image, float x, float y, float width, float height)
743 throw new ArgumentNullException ("image");
744 Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
746 GDIPlus.CheckStatus (status);
749 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit,
750 ImageAttributes imageAttr)
753 throw new ArgumentNullException ("image");
754 if (destPoints == null)
755 throw new ArgumentNullException ("destPoints");
756 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
757 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
758 srcRect.Width, srcRect.Height, srcUnit,
759 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
760 GDIPlus.CheckStatus (status);
763 public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
766 throw new ArgumentNullException ("image");
767 Status status = GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
768 GDIPlus.CheckStatus (status);
771 public void DrawImage (Image image, int x, int y, int width, int height)
774 throw new ArgumentNullException ("image");
775 Status status = GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
776 GDIPlus.CheckStatus (status);
779 public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
782 throw new ArgumentNullException ("image");
783 Status status = GDIPlus.GdipDrawImagePointRect (nativeObject, image.nativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
784 GDIPlus.CheckStatus (status);
787 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
790 throw new ArgumentNullException ("image");
791 if (destPoints == null)
792 throw new ArgumentNullException ("destPoints");
793 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
794 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
795 srcRect.Width, srcRect.Height, srcUnit,
796 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
797 GDIPlus.CheckStatus (status);
800 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
803 throw new ArgumentNullException ("image");
804 if (destPoints == null)
805 throw new ArgumentNullException ("destPoints");
807 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
808 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
809 srcRect.Width, srcRect.Height, srcUnit,
810 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
811 GDIPlus.CheckStatus (status);
814 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
817 throw new ArgumentNullException ("image");
818 if (destPoints == null)
819 throw new ArgumentNullException ("destPoints");
821 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
822 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
823 srcRect.Width, srcRect.Height, srcUnit,
824 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
825 GDIPlus.CheckStatus (status);
828 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
831 throw new ArgumentNullException ("image");
832 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
833 destRect.X, destRect.Y, destRect.Width, destRect.Height,
834 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero,
836 GDIPlus.CheckStatus (status);
839 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
841 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
842 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
843 srcRect.Width, srcRect.Height, srcUnit,
844 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
845 GDIPlus.CheckStatus (status);
848 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
851 throw new ArgumentNullException ("image");
852 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
853 destRect.X, destRect.Y, destRect.Width, destRect.Height,
854 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero,
856 GDIPlus.CheckStatus (status);
859 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
862 throw new ArgumentNullException ("image");
863 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
864 destRect.X, destRect.Y, destRect.Width, destRect.Height,
865 srcX, srcY, srcWidth, srcHeight, srcUnit,
866 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
867 GDIPlus.CheckStatus (status);
870 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
873 throw new ArgumentNullException ("image");
874 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
875 destRect.X, destRect.Y, destRect.Width,
876 destRect.Height, srcX, srcY, srcWidth, srcHeight,
877 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
878 GDIPlus.CheckStatus (status);
881 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
884 throw new ArgumentNullException ("image");
885 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
886 destRect.X, destRect.Y, destRect.Width,
887 destRect.Height, srcX, srcY, srcWidth, srcHeight,
888 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback,
890 GDIPlus.CheckStatus (status);
893 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
896 throw new ArgumentNullException ("image");
897 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
898 destRect.X, destRect.Y, destRect.Width,
899 destRect.Height, srcX, srcY, srcWidth, srcHeight,
900 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero,
901 callback, IntPtr.Zero);
902 GDIPlus.CheckStatus (status);
905 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
908 throw new ArgumentNullException ("image");
909 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
910 destRect.X, destRect.Y, destRect.Width, destRect.Height,
911 srcX, srcY, srcWidth, srcHeight, srcUnit,
912 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, callbackData);
913 GDIPlus.CheckStatus (status);
916 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
919 throw new ArgumentNullException ("image");
920 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
921 destRect.X, destRect.Y, destRect.Width, destRect.Height,
922 srcX, srcY, srcWidth, srcHeight, srcUnit,
923 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, callbackData);
924 GDIPlus.CheckStatus (status);
927 public void DrawImageUnscaled (Image image, Point point)
929 DrawImageUnscaled (image, point.X, point.Y);
932 public void DrawImageUnscaled (Image image, Rectangle rect)
934 DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
937 public void DrawImageUnscaled (Image image, int x, int y)
940 throw new ArgumentNullException ("image");
941 DrawImage (image, x, y, image.Width, image.Height);
944 public void DrawImageUnscaled (Image image, int x, int y, int width, int height)
947 throw new ArgumentNullException ("image");
949 // avoid creating an empty, or negative w/h, bitmap...
950 if ((width <= 0) || (height <= 0))
953 using (Image tmpImg = new Bitmap (width, height)) {
954 using (Graphics g = FromImage (tmpImg)) {
955 g.DrawImage (image, 0, 0, image.Width, image.Height);
956 DrawImage (tmpImg, x, y, width, height);
962 public void DrawImageUnscaledAndClipped (Image image, Rectangle rect)
965 throw new ArgumentNullException ("image");
967 int width = (image.Width > rect.Width) ? rect.Width : image.Width;
968 int height = (image.Height > rect.Height) ? rect.Height : image.Height;
970 DrawImageUnscaled (image, rect.X, rect.Y, width, height);
974 public void DrawLine (Pen pen, PointF pt1, PointF pt2)
977 throw new ArgumentNullException ("pen");
978 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject,
979 pt1.X, pt1.Y, pt2.X, pt2.Y);
980 GDIPlus.CheckStatus (status);
983 public void DrawLine (Pen pen, Point pt1, Point pt2)
986 throw new ArgumentNullException ("pen");
987 Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject,
988 pt1.X, pt1.Y, pt2.X, pt2.Y);
989 GDIPlus.CheckStatus (status);
992 public void DrawLine (Pen pen, int x1, int y1, int x2, int y2)
995 throw new ArgumentNullException ("pen");
996 Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);
997 GDIPlus.CheckStatus (status);
1000 public void DrawLine (Pen pen, float x1, float y1, float x2, float y2)
1003 throw new ArgumentNullException ("pen");
1004 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);
1005 GDIPlus.CheckStatus (status);
1008 public void DrawLines (Pen pen, PointF [] points)
1011 throw new ArgumentNullException ("pen");
1013 throw new ArgumentNullException ("points");
1014 Status status = GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);
1015 GDIPlus.CheckStatus (status);
1018 public void DrawLines (Pen pen, Point [] points)
1021 throw new ArgumentNullException ("pen");
1023 throw new ArgumentNullException ("points");
1024 Status status = GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);
1025 GDIPlus.CheckStatus (status);
1028 public void DrawPath (Pen pen, GraphicsPath path)
1031 throw new ArgumentNullException ("pen");
1033 throw new ArgumentNullException ("path");
1034 Status status = GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
1035 GDIPlus.CheckStatus (status);
1038 public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
1041 throw new ArgumentNullException ("pen");
1042 DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1045 public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
1048 throw new ArgumentNullException ("pen");
1049 DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1052 public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
1055 throw new ArgumentNullException ("pen");
1056 Status status = GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1057 GDIPlus.CheckStatus (status);
1060 // Microsoft documentation states that the signature for this member should be
1061 // public void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle
1062 // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
1063 public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
1066 throw new ArgumentNullException ("pen");
1067 Status status = GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1068 GDIPlus.CheckStatus (status);
1071 public void DrawPolygon (Pen pen, Point [] points)
1074 throw new ArgumentNullException ("pen");
1076 throw new ArgumentNullException ("points");
1077 Status status = GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
1078 GDIPlus.CheckStatus (status);
1081 public void DrawPolygon (Pen pen, PointF [] points)
1084 throw new ArgumentNullException ("pen");
1086 throw new ArgumentNullException ("points");
1087 Status status = GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
1088 GDIPlus.CheckStatus (status);
1091 internal void DrawRectangle (Pen pen, RectangleF rect)
1094 throw new ArgumentNullException ("pen");
1095 DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
1098 public void DrawRectangle (Pen pen, Rectangle rect)
1101 throw new ArgumentNullException ("pen");
1102 DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
1105 public void DrawRectangle (Pen pen, float x, float y, float width, float height)
1108 throw new ArgumentNullException ("pen");
1109 Status status = GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
1110 GDIPlus.CheckStatus (status);
1113 public void DrawRectangle (Pen pen, int x, int y, int width, int height)
1116 throw new ArgumentNullException ("pen");
1117 Status status = GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
1118 GDIPlus.CheckStatus (status);
1121 public void DrawRectangles (Pen pen, RectangleF [] rects)
1124 throw new ArgumentNullException ("image");
1126 throw new ArgumentNullException ("rects");
1127 Status status = GDIPlus.GdipDrawRectangles (nativeObject, pen.nativeObject, rects, rects.Length);
1128 GDIPlus.CheckStatus (status);
1131 public void DrawRectangles (Pen pen, Rectangle [] rects)
1134 throw new ArgumentNullException ("image");
1136 throw new ArgumentNullException ("rects");
1137 Status status = GDIPlus.GdipDrawRectanglesI (nativeObject, pen.nativeObject, rects, rects.Length);
1138 GDIPlus.CheckStatus (status);
1141 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle)
1143 DrawString (s, font, brush, layoutRectangle, null);
1146 public void DrawString (string s, Font font, Brush brush, PointF point)
1148 DrawString (s, font, brush, new RectangleF (point.X, point.Y, 0, 0), null);
1151 public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format)
1153 DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
1156 public void DrawString (string s, Font font, Brush brush, float x, float y)
1158 DrawString (s, font, brush, new RectangleF (x, y, 0, 0), null);
1161 public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format)
1163 DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
1166 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
1169 throw new ArgumentNullException ("font");
1171 throw new ArgumentNullException ("brush");
1172 if (s == null || s.Length == 0)
1175 Status status = GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, format != null ? format.NativeObject : IntPtr.Zero, brush.nativeObject);
1176 GDIPlus.CheckStatus (status);
1179 public void EndContainer (GraphicsContainer container)
1182 if (container == null)
1183 throw new ArgumentNullException ("container");
1185 Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
1186 GDIPlus.CheckStatus (status);
1189 private const string MetafileEnumeration = "Metafiles enumeration, for both WMF and EMF formats, isn't supported.";
1191 [MonoTODO (MetafileEnumeration)]
1192 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
1194 throw new NotImplementedException ();
1197 [MonoTODO (MetafileEnumeration)]
1198 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
1200 throw new NotImplementedException ();
1203 [MonoTODO (MetafileEnumeration)]
1204 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
1206 throw new NotImplementedException ();
1209 [MonoTODO (MetafileEnumeration)]
1210 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
1212 throw new NotImplementedException ();
1215 [MonoTODO (MetafileEnumeration)]
1216 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
1218 throw new NotImplementedException ();
1221 [MonoTODO (MetafileEnumeration)]
1222 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
1224 throw new NotImplementedException ();
1227 [MonoTODO (MetafileEnumeration)]
1228 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1230 throw new NotImplementedException ();
1233 [MonoTODO (MetafileEnumeration)]
1234 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1236 throw new NotImplementedException ();
1239 [MonoTODO (MetafileEnumeration)]
1240 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1242 throw new NotImplementedException ();
1245 [MonoTODO (MetafileEnumeration)]
1246 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1248 throw new NotImplementedException ();
1251 [MonoTODO (MetafileEnumeration)]
1252 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1254 throw new NotImplementedException ();
1257 [MonoTODO (MetafileEnumeration)]
1258 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1260 throw new NotImplementedException ();
1263 [MonoTODO (MetafileEnumeration)]
1264 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1266 throw new NotImplementedException ();
1269 [MonoTODO (MetafileEnumeration)]
1270 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1272 throw new NotImplementedException ();
1275 [MonoTODO (MetafileEnumeration)]
1276 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1278 throw new NotImplementedException ();
1281 [MonoTODO (MetafileEnumeration)]
1282 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1284 throw new NotImplementedException ();
1287 [MonoTODO (MetafileEnumeration)]
1288 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1290 throw new NotImplementedException ();
1293 [MonoTODO (MetafileEnumeration)]
1294 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1296 throw new NotImplementedException ();
1299 [MonoTODO (MetafileEnumeration)]
1300 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1302 throw new NotImplementedException ();
1305 [MonoTODO (MetafileEnumeration)]
1306 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1308 throw new NotImplementedException ();
1311 [MonoTODO (MetafileEnumeration)]
1312 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1314 throw new NotImplementedException ();
1317 [MonoTODO (MetafileEnumeration)]
1318 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1320 throw new NotImplementedException ();
1323 [MonoTODO (MetafileEnumeration)]
1324 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1326 throw new NotImplementedException ();
1329 [MonoTODO (MetafileEnumeration)]
1330 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1332 throw new NotImplementedException ();
1335 [MonoTODO (MetafileEnumeration)]
1336 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1338 throw new NotImplementedException ();
1341 [MonoTODO (MetafileEnumeration)]
1342 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1344 throw new NotImplementedException ();
1347 [MonoTODO (MetafileEnumeration)]
1348 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1350 throw new NotImplementedException ();
1353 [MonoTODO (MetafileEnumeration)]
1354 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1356 throw new NotImplementedException ();
1359 [MonoTODO (MetafileEnumeration)]
1360 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1362 throw new NotImplementedException ();
1365 [MonoTODO (MetafileEnumeration)]
1366 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1368 throw new NotImplementedException ();
1371 [MonoTODO (MetafileEnumeration)]
1372 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1374 throw new NotImplementedException ();
1377 [MonoTODO (MetafileEnumeration)]
1378 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1380 throw new NotImplementedException ();
1383 [MonoTODO (MetafileEnumeration)]
1384 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1386 throw new NotImplementedException ();
1389 [MonoTODO (MetafileEnumeration)]
1390 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1392 throw new NotImplementedException ();
1395 [MonoTODO (MetafileEnumeration)]
1396 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1398 throw new NotImplementedException ();
1401 [MonoTODO (MetafileEnumeration)]
1402 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1404 throw new NotImplementedException ();
1407 public void ExcludeClip (Rectangle rect)
1409 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);
1410 GDIPlus.CheckStatus (status);
1413 public void ExcludeClip (Region region)
1416 throw new ArgumentNullException ("region");
1417 Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Exclude);
1418 GDIPlus.CheckStatus (status);
1422 public void FillClosedCurve (Brush brush, PointF [] points)
1425 throw new ArgumentNullException ("brush");
1427 throw new ArgumentNullException ("points");
1428 Status status = GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
1429 GDIPlus.CheckStatus (status);
1432 public void FillClosedCurve (Brush brush, Point [] points)
1435 throw new ArgumentNullException ("brush");
1437 throw new ArgumentNullException ("points");
1438 Status status = GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
1439 GDIPlus.CheckStatus (status);
1443 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode)
1446 throw new ArgumentNullException ("brush");
1448 throw new ArgumentNullException ("points");
1449 FillClosedCurve (brush, points, fillmode, 0.5f);
1452 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode)
1455 throw new ArgumentNullException ("brush");
1457 throw new ArgumentNullException ("points");
1458 FillClosedCurve (brush, points, fillmode, 0.5f);
1461 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension)
1464 throw new ArgumentNullException ("brush");
1466 throw new ArgumentNullException ("points");
1467 Status status = GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1468 GDIPlus.CheckStatus (status);
1471 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension)
1474 throw new ArgumentNullException ("brush");
1476 throw new ArgumentNullException ("points");
1477 Status status = GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1478 GDIPlus.CheckStatus (status);
1481 public void FillEllipse (Brush brush, Rectangle rect)
1484 throw new ArgumentNullException ("brush");
1485 FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1488 public void FillEllipse (Brush brush, RectangleF rect)
1491 throw new ArgumentNullException ("brush");
1492 FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1495 public void FillEllipse (Brush brush, float x, float y, float width, float height)
1498 throw new ArgumentNullException ("brush");
1499 Status status = GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
1500 GDIPlus.CheckStatus (status);
1503 public void FillEllipse (Brush brush, int x, int y, int width, int height)
1506 throw new ArgumentNullException ("brush");
1507 Status status = GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
1508 GDIPlus.CheckStatus (status);
1511 public void FillPath (Brush brush, GraphicsPath path)
1514 throw new ArgumentNullException ("brush");
1516 throw new ArgumentNullException ("path");
1517 Status status = GDIPlus.GdipFillPath (nativeObject, brush.NativeObject, path.NativeObject);
1518 GDIPlus.CheckStatus (status);
1521 public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)
1524 throw new ArgumentNullException ("brush");
1525 Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1526 GDIPlus.CheckStatus (status);
1529 public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
1532 throw new ArgumentNullException ("brush");
1533 Status status = GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1534 GDIPlus.CheckStatus (status);
1537 public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
1540 throw new ArgumentNullException ("brush");
1541 Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1542 GDIPlus.CheckStatus (status);
1545 public void FillPolygon (Brush brush, PointF [] points)
1548 throw new ArgumentNullException ("brush");
1550 throw new ArgumentNullException ("points");
1551 Status status = GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
1552 GDIPlus.CheckStatus (status);
1555 public void FillPolygon (Brush brush, Point [] points)
1558 throw new ArgumentNullException ("brush");
1560 throw new ArgumentNullException ("points");
1561 Status status = GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
1562 GDIPlus.CheckStatus (status);
1565 public void FillPolygon (Brush brush, Point [] points, FillMode fillMode)
1568 throw new ArgumentNullException ("brush");
1570 throw new ArgumentNullException ("points");
1571 Status status = GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1572 GDIPlus.CheckStatus (status);
1575 public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode)
1578 throw new ArgumentNullException ("brush");
1580 throw new ArgumentNullException ("points");
1581 Status status = GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1582 GDIPlus.CheckStatus (status);
1585 public void FillRectangle (Brush brush, RectangleF rect)
1588 throw new ArgumentNullException ("brush");
1589 FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1592 public void FillRectangle (Brush brush, Rectangle rect)
1595 throw new ArgumentNullException ("brush");
1596 FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1599 public void FillRectangle (Brush brush, int x, int y, int width, int height)
1602 throw new ArgumentNullException ("brush");
1604 Status status = GDIPlus.GdipFillRectangleI (nativeObject, brush.nativeObject, x, y, width, height);
1605 GDIPlus.CheckStatus (status);
1608 public void FillRectangle (Brush brush, float x, float y, float width, float height)
1611 throw new ArgumentNullException ("brush");
1613 Status status = GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
1614 GDIPlus.CheckStatus (status);
1617 public void FillRectangles (Brush brush, Rectangle [] rects)
1620 throw new ArgumentNullException ("brush");
1622 throw new ArgumentNullException ("rects");
1624 Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
1625 GDIPlus.CheckStatus (status);
1628 public void FillRectangles (Brush brush, RectangleF [] rects)
1631 throw new ArgumentNullException ("brush");
1633 throw new ArgumentNullException ("rects");
1635 Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
1636 GDIPlus.CheckStatus (status);
1640 public void FillRegion (Brush brush, Region region)
1643 throw new ArgumentNullException ("brush");
1645 throw new ArgumentNullException ("region");
1647 Status status = GDIPlus.GdipFillRegion (nativeObject, brush.NativeObject, region.NativeObject);
1648 GDIPlus.CheckStatus(status);
1652 public void Flush ()
1654 Flush (FlushIntention.Flush);
1658 public void Flush (FlushIntention intention)
1660 if (nativeObject == IntPtr.Zero) {
1664 Status status = GDIPlus.GdipFlush (nativeObject, intention);
1665 GDIPlus.CheckStatus (status);
1666 if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero)
1667 Carbon.CGContextSynchronize (context.ctx);
1670 [EditorBrowsable (EditorBrowsableState.Advanced)]
1671 public static Graphics FromHdc (IntPtr hdc)
1674 Status status = GDIPlus.GdipCreateFromHDC (hdc, out graphics);
1675 GDIPlus.CheckStatus (status);
1676 return new Graphics (graphics);
1680 [EditorBrowsable (EditorBrowsableState.Advanced)]
1681 public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
1683 throw new NotImplementedException ();
1686 [EditorBrowsable (EditorBrowsableState.Advanced)]
1687 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1688 public static Graphics FromHdcInternal (IntPtr hdc)
1690 GDIPlus.Display = hdc;
1694 [EditorBrowsable (EditorBrowsableState.Advanced)]
1695 public static Graphics FromHwnd (IntPtr hwnd)
1699 if (GDIPlus.UseCocoaDrawable) {
1700 throw new NotImplementedException ();
1701 /* TODO: Fix this code to handle the new libgdiplus
1702 CarbonContext context = Carbon.GetCGContextForNSView (hwnd);
1703 GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
1705 Graphics g = new Graphics (graphics);
1706 g.context = context;
1711 if (GDIPlus.UseQuartzDrawable) {
1712 CarbonContext context = Carbon.GetCGContextForView (hwnd);
1713 GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
1715 Graphics g = new Graphics (graphics);
1716 g.context = context;
1720 if (GDIPlus.UseX11Drawable) {
1721 if (GDIPlus.Display == IntPtr.Zero) {
1722 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
1725 return FromXDrawable (hwnd, GDIPlus.Display);
1729 Status status = GDIPlus.GdipCreateFromHWND (hwnd, out graphics);
1730 GDIPlus.CheckStatus (status);
1732 return new Graphics (graphics);
1735 [EditorBrowsable (EditorBrowsableState.Advanced)]
1736 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1737 public static Graphics FromHwndInternal (IntPtr hwnd)
1739 return FromHwnd (hwnd);
1742 public static Graphics FromImage (Image image)
1747 throw new ArgumentNullException ("image");
1749 if ((image.PixelFormat & PixelFormat.Indexed) != 0)
1750 throw new Exception (Locale.GetText ("Cannot create Graphics from an indexed bitmap."));
1752 Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
1753 GDIPlus.CheckStatus (status);
1754 Graphics result = new Graphics (graphics);
1756 if (GDIPlus.RunningOnUnix ()) {
1757 Rectangle rect = new Rectangle (0,0, image.Width, image.Height);
1758 GDIPlus.GdipSetVisibleClip_linux (result.NativeObject, ref rect);
1764 internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
1768 Status s = GDIPlus.GdipCreateFromXDrawable_linux (drawable, display, out graphics);
1769 GDIPlus.CheckStatus (s);
1770 return new Graphics (graphics);
1774 public static IntPtr GetHalftonePalette ()
1776 throw new NotImplementedException ();
1780 [EditorBrowsable (EditorBrowsableState.Advanced)]
1782 public IntPtr GetHdc ()
1784 GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out deviceContextHdc));
1785 return deviceContextHdc;
1788 public Color GetNearestColor (Color color)
1792 Status status = GDIPlus.GdipGetNearestColor (nativeObject, out argb);
1793 GDIPlus.CheckStatus (status);
1795 return Color.FromArgb (argb);
1799 public void IntersectClip (Region region)
1802 throw new ArgumentNullException ("region");
1803 Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Intersect);
1804 GDIPlus.CheckStatus (status);
1807 public void IntersectClip (RectangleF rect)
1809 Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1810 GDIPlus.CheckStatus (status);
1813 public void IntersectClip (Rectangle rect)
1815 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1816 GDIPlus.CheckStatus (status);
1819 public bool IsVisible (Point point)
1821 bool isVisible = false;
1823 Status status = GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
1824 GDIPlus.CheckStatus (status);
1830 public bool IsVisible (RectangleF rect)
1832 bool isVisible = false;
1834 Status status = GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1835 GDIPlus.CheckStatus (status);
1840 public bool IsVisible (PointF point)
1842 bool isVisible = false;
1844 Status status = GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
1845 GDIPlus.CheckStatus (status);
1850 public bool IsVisible (Rectangle rect)
1852 bool isVisible = false;
1854 Status status = GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1855 GDIPlus.CheckStatus (status);
1860 public bool IsVisible (float x, float y)
1862 return IsVisible (new PointF (x, y));
1865 public bool IsVisible (int x, int y)
1867 return IsVisible (new Point (x, y));
1870 public bool IsVisible (float x, float y, float width, float height)
1872 return IsVisible (new RectangleF (x, y, width, height));
1876 public bool IsVisible (int x, int y, int width, int height)
1878 return IsVisible (new Rectangle (x, y, width, height));
1882 public Region[] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
1884 if ((text == null) || (text.Length == 0))
1885 return new Region [0];
1888 throw new ArgumentNullException ("font");
1890 if (stringFormat == null)
1891 throw new ArgumentException ("stringFormat");
1893 int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
1895 return new Region[0];
1897 IntPtr[] native_regions = new IntPtr [regcount];
1898 Region[] regions = new Region [regcount];
1900 for (int i = 0; i < regcount; i++) {
1901 regions[i] = new Region ();
1902 native_regions[i] = regions[i].NativeObject;
1905 Status status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
1906 font.NativeObject, ref layoutRect, stringFormat.NativeObject, regcount, out native_regions[0]);
1907 GDIPlus.CheckStatus (status);
1912 private unsafe SizeF GdipMeasureString (IntPtr graphics, string text, Font font, ref RectangleF layoutRect,
1913 IntPtr stringFormat)
1915 if ((text == null) || (text.Length == 0))
1919 throw new ArgumentNullException ("font");
1921 RectangleF boundingBox = new RectangleF ();
1923 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject,
1924 ref layoutRect, stringFormat, out boundingBox, null, null);
1925 GDIPlus.CheckStatus (status);
1927 return new SizeF (boundingBox.Width, boundingBox.Height);
1930 public SizeF MeasureString (string text, Font font)
1932 return MeasureString (text, font, SizeF.Empty);
1935 public SizeF MeasureString (string text, Font font, SizeF layoutArea)
1937 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1938 return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1941 public SizeF MeasureString (string text, Font font, int width)
1943 RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1944 return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1947 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat)
1949 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1950 IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1951 return GdipMeasureString (nativeObject, text, font, ref rect, format);
1954 public SizeF MeasureString (string text, Font font, int width, StringFormat format)
1956 RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1957 IntPtr stringFormat = (format == null) ? IntPtr.Zero : format.NativeObject;
1958 return GdipMeasureString (nativeObject, text, font, ref rect, stringFormat);
1961 public SizeF MeasureString (string text, Font font, PointF origin, StringFormat stringFormat)
1963 RectangleF rect = new RectangleF (origin.X, origin.Y, 0, 0);
1964 IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1965 return GdipMeasureString (nativeObject, text, font, ref rect, format);
1968 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat,
1969 out int charactersFitted, out int linesFilled)
1971 charactersFitted = 0;
1974 if ((text == null) || (text.Length == 0))
1978 throw new ArgumentNullException ("font");
1980 RectangleF boundingBox = new RectangleF ();
1981 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1983 IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1986 fixed (int* pc = &charactersFitted, pl = &linesFilled) {
1987 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
1988 font.NativeObject, ref rect, format, out boundingBox, pc, pl);
1989 GDIPlus.CheckStatus (status);
1992 return new SizeF (boundingBox.Width, boundingBox.Height);
1995 public void MultiplyTransform (Matrix matrix)
1997 MultiplyTransform (matrix, MatrixOrder.Prepend);
2000 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
2003 throw new ArgumentNullException ("matrix");
2005 Status status = GDIPlus.GdipMultiplyWorldTransform (nativeObject, matrix.nativeMatrix, order);
2006 GDIPlus.CheckStatus (status);
2009 [EditorBrowsable (EditorBrowsableState.Advanced)]
2010 [SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
2011 public void ReleaseHdc (IntPtr hdc)
2013 ReleaseHdcInternal (hdc);
2017 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2018 public void ReleaseHdc ()
2020 ReleaseHdcInternal (deviceContextHdc);
2024 [MonoLimitation ("Can only be used when hdc was provided by Graphics.GetHdc() method")]
2026 [EditorBrowsable (EditorBrowsableState.Never)]
2028 [EditorBrowsable (EditorBrowsableState.Advanced)]
2030 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2031 public void ReleaseHdcInternal (IntPtr hdc)
2033 Status status = Status.InvalidParameter;
2034 if (hdc == deviceContextHdc) {
2035 status = GDIPlus.GdipReleaseDC (nativeObject, deviceContextHdc);
2036 deviceContextHdc = IntPtr.Zero;
2038 GDIPlus.CheckStatus (status);
2041 public void ResetClip ()
2043 Status status = GDIPlus.GdipResetClip (nativeObject);
2044 GDIPlus.CheckStatus (status);
2047 public void ResetTransform ()
2049 Status status = GDIPlus.GdipResetWorldTransform (nativeObject);
2050 GDIPlus.CheckStatus (status);
2053 public void Restore (GraphicsState gstate)
2055 // the possible NRE thrown by gstate.nativeState match MS behaviour
2056 Status status = GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
2057 GDIPlus.CheckStatus (status);
2060 public void RotateTransform (float angle)
2062 RotateTransform (angle, MatrixOrder.Prepend);
2065 public void RotateTransform (float angle, MatrixOrder order)
2067 Status status = GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
2068 GDIPlus.CheckStatus (status);
2071 public GraphicsState Save ()
2074 Status status = GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
2075 GDIPlus.CheckStatus (status);
2077 GraphicsState state = new GraphicsState ();
2078 state.nativeState = saveState;
2082 public void ScaleTransform (float sx, float sy)
2084 ScaleTransform (sx, sy, MatrixOrder.Prepend);
2087 public void ScaleTransform (float sx, float sy, MatrixOrder order)
2089 Status status = GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
2090 GDIPlus.CheckStatus (status);
2094 public void SetClip (RectangleF rect)
2096 SetClip (rect, CombineMode.Replace);
2100 public void SetClip (GraphicsPath path)
2102 SetClip (path, CombineMode.Replace);
2106 public void SetClip (Rectangle rect)
2108 SetClip (rect, CombineMode.Replace);
2112 public void SetClip (Graphics g)
2114 SetClip (g, CombineMode.Replace);
2118 public void SetClip (Graphics g, CombineMode combineMode)
2121 throw new ArgumentNullException ("g");
2123 Status status = GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
2124 GDIPlus.CheckStatus (status);
2128 public void SetClip (Rectangle rect, CombineMode combineMode)
2130 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2131 GDIPlus.CheckStatus (status);
2135 public void SetClip (RectangleF rect, CombineMode combineMode)
2137 Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2138 GDIPlus.CheckStatus (status);
2142 public void SetClip (Region region, CombineMode combineMode)
2145 throw new ArgumentNullException ("region");
2146 Status status = GDIPlus.GdipSetClipRegion(nativeObject, region.NativeObject, combineMode);
2147 GDIPlus.CheckStatus (status);
2151 public void SetClip (GraphicsPath path, CombineMode combineMode)
2154 throw new ArgumentNullException ("path");
2155 Status status = GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
2156 GDIPlus.CheckStatus (status);
2160 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts)
2163 throw new ArgumentNullException ("pts");
2165 IntPtr ptrPt = GDIPlus.FromPointToUnManagedMemory (pts);
2167 Status status = GDIPlus.GdipTransformPoints (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2168 GDIPlus.CheckStatus (status);
2170 GDIPlus.FromUnManagedMemoryToPoint (ptrPt, pts);
2174 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
2177 throw new ArgumentNullException ("pts");
2178 IntPtr ptrPt = GDIPlus.FromPointToUnManagedMemoryI (pts);
2180 Status status = GDIPlus.GdipTransformPointsI (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2181 GDIPlus.CheckStatus (status);
2183 GDIPlus.FromUnManagedMemoryToPointI (ptrPt, pts);
2187 public void TranslateClip (int dx, int dy)
2189 Status status = GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);
2190 GDIPlus.CheckStatus (status);
2194 public void TranslateClip (float dx, float dy)
2196 Status status = GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
2197 GDIPlus.CheckStatus (status);
2200 public void TranslateTransform (float dx, float dy)
2202 TranslateTransform (dx, dy, MatrixOrder.Prepend);
2206 public void TranslateTransform (float dx, float dy, MatrixOrder order)
2208 Status status = GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
2209 GDIPlus.CheckStatus (status);
2212 public Region Clip {
2214 Region reg = new Region();
2215 Status status = GDIPlus.GdipGetClip (nativeObject, reg.NativeObject);
2216 GDIPlus.CheckStatus (status);
2220 SetClip (value, CombineMode.Replace);
2224 public RectangleF ClipBounds {
2226 RectangleF rect = new RectangleF ();
2227 Status status = GDIPlus.GdipGetClipBounds (nativeObject, out rect);
2228 GDIPlus.CheckStatus (status);
2233 public CompositingMode CompositingMode {
2235 CompositingMode mode;
2236 Status status = GDIPlus.GdipGetCompositingMode (nativeObject, out mode);
2237 GDIPlus.CheckStatus (status);
2242 Status status = GDIPlus.GdipSetCompositingMode (nativeObject, value);
2243 GDIPlus.CheckStatus (status);
2248 public CompositingQuality CompositingQuality {
2250 CompositingQuality quality;
2252 Status status = GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
2253 GDIPlus.CheckStatus (status);
2257 Status status = GDIPlus.GdipSetCompositingQuality (nativeObject, value);
2258 GDIPlus.CheckStatus (status);
2266 Status status = GDIPlus.GdipGetDpiX (nativeObject, out x);
2267 GDIPlus.CheckStatus (status);
2276 Status status = GDIPlus.GdipGetDpiY (nativeObject, out y);
2277 GDIPlus.CheckStatus (status);
2282 public InterpolationMode InterpolationMode {
2284 InterpolationMode imode = InterpolationMode.Invalid;
2285 Status status = GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
2286 GDIPlus.CheckStatus (status);
2290 Status status = GDIPlus.GdipSetInterpolationMode (nativeObject, value);
2291 GDIPlus.CheckStatus (status);
2295 public bool IsClipEmpty {
2297 bool isEmpty = false;
2299 Status status = GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
2300 GDIPlus.CheckStatus (status);
2305 public bool IsVisibleClipEmpty {
2307 bool isEmpty = false;
2309 Status status = GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
2310 GDIPlus.CheckStatus (status);
2315 public float PageScale {
2319 Status status = GDIPlus.GdipGetPageScale (nativeObject, out scale);
2320 GDIPlus.CheckStatus (status);
2324 Status status = GDIPlus.GdipSetPageScale (nativeObject, value);
2325 GDIPlus.CheckStatus (status);
2329 public GraphicsUnit PageUnit {
2333 Status status = GDIPlus.GdipGetPageUnit (nativeObject, out unit);
2334 GDIPlus.CheckStatus (status);
2338 Status status = GDIPlus.GdipSetPageUnit (nativeObject, value);
2339 GDIPlus.CheckStatus (status);
2343 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2344 public PixelOffsetMode PixelOffsetMode {
2346 PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
2348 Status status = GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
2349 GDIPlus.CheckStatus (status);
2353 Status status = GDIPlus.GdipSetPixelOffsetMode (nativeObject, value);
2354 GDIPlus.CheckStatus (status);
2358 public Point RenderingOrigin {
2361 Status status = GDIPlus.GdipGetRenderingOrigin (nativeObject, out x, out y);
2362 GDIPlus.CheckStatus (status);
2363 return new Point (x, y);
2367 Status status = GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
2368 GDIPlus.CheckStatus (status);
2372 public SmoothingMode SmoothingMode {
2374 SmoothingMode mode = SmoothingMode.Invalid;
2376 Status status = GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
2377 GDIPlus.CheckStatus (status);
2382 Status status = GDIPlus.GdipSetSmoothingMode (nativeObject, value);
2383 GDIPlus.CheckStatus (status);
2387 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2388 public int TextContrast {
2392 Status status = GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
2393 GDIPlus.CheckStatus (status);
2398 Status status = GDIPlus.GdipSetTextContrast (nativeObject, value);
2399 GDIPlus.CheckStatus (status);
2403 public TextRenderingHint TextRenderingHint {
2405 TextRenderingHint hint;
2407 Status status = GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
2408 GDIPlus.CheckStatus (status);
2413 Status status = GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
2414 GDIPlus.CheckStatus (status);
2418 public Matrix Transform {
2420 Matrix matrix = new Matrix ();
2421 Status status = GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
2422 GDIPlus.CheckStatus (status);
2427 throw new ArgumentNullException ("value");
2429 Status status = GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
2430 GDIPlus.CheckStatus (status);
2434 public RectangleF VisibleClipBounds {
2438 Status status = GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
2439 GDIPlus.CheckStatus (status);
2446 [EditorBrowsable (EditorBrowsableState.Never)]
2447 public object GetContextInfo ()
2449 // only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
2450 throw new NotImplementedException ();