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)
9 // Copyright (C) 2003 Ximian, Inc. (http://www.ximian.com)
11 // Copyright (C) 2004-2005 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
44 public sealed class Graphics : MarshalByRefObject, IDisposable
46 internal IntPtr nativeObject = IntPtr.Zero;
47 private bool disposed = false;
48 private static float defDpiX = 0;
49 private static float defDpiY = 0;
52 public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
56 PlayRecordCallback callbackData);
59 public delegate bool DrawImageAbort (IntPtr callbackData);
61 private Graphics (IntPtr nativeGraphics)
63 nativeObject = nativeGraphics;
71 static internal float systemDpiX {
74 Bitmap bmp = new Bitmap (1, 1);
75 Graphics g = Graphics.FromImage (bmp);
82 static internal float systemDpiY {
85 Bitmap bmp = new Bitmap (1, 1);
86 Graphics g = Graphics.FromImage (bmp);
93 internal IntPtr NativeObject {
104 public void AddMetafileComment (byte [] data)
106 throw new NotImplementedException ();
110 public GraphicsContainer BeginContainer ()
114 status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
115 GDIPlus.CheckStatus (status);
117 return new GraphicsContainer(state);
120 public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
124 status = GDIPlus.GdipBeginContainerI (nativeObject, dstrect, srcrect, unit, out state);
125 GDIPlus.CheckStatus (status);
127 return new GraphicsContainer (state);
131 public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
135 status = GDIPlus.GdipBeginContainer (nativeObject, dstrect, srcrect, unit, out state);
136 GDIPlus.CheckStatus (status);
138 return new GraphicsContainer (state);
142 public void Clear (Color color)
145 status = GDIPlus.GdipGraphicsClear (nativeObject, color.ToArgb ());
146 GDIPlus.CheckStatus (status);
149 public void Dispose ()
153 status = GDIPlus.GdipDeleteGraphics (nativeObject);
154 nativeObject = IntPtr.Zero;
155 GDIPlus.CheckStatus (status);
158 GC.SuppressFinalize(this);
162 public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
164 DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
168 public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
170 DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
174 public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
178 throw new ArgumentNullException ("pen");
180 status = GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
181 x, y, width, height, startAngle, sweepAngle);
182 GDIPlus.CheckStatus (status);
185 // Microsoft documentation states that the signature for this member should be
186 // public void DrawArc( Pen pen, int x, int y, int width, int height, int startAngle,
187 // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
188 public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
192 throw new ArgumentNullException ("pen");
193 status = GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
194 x, y, width, height, startAngle, sweepAngle);
195 GDIPlus.CheckStatus (status);
198 public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
202 throw new ArgumentNullException ("pen");
203 status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
204 pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
205 pt3.Y, pt4.X, pt4.Y);
206 GDIPlus.CheckStatus (status);
209 public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
213 throw new ArgumentNullException ("pen");
214 status = GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject,
215 pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
216 pt3.Y, pt4.X, pt4.Y);
217 GDIPlus.CheckStatus (status);
220 public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
224 throw new ArgumentNullException ("pen");
225 status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1,
226 y1, x2, y2, x3, y3, x4, y4);
227 GDIPlus.CheckStatus (status);
230 public void DrawBeziers (Pen pen, Point [] points)
233 throw new ArgumentNullException ("pen");
235 throw new ArgumentNullException ("points");
237 int length = points.Length;
243 for (int i = 0; i < length; i += 3) {
244 Point p1 = points [i];
245 Point p2 = points [i + 1];
246 Point p3 = points [i + 2];
247 Point p4 = points [i + 3];
249 status = GDIPlus.GdipDrawBezier (nativeObject,
251 p1.X, p1.Y, p2.X, p2.Y,
252 p3.X, p3.Y, p4.X, p4.Y);
253 GDIPlus.CheckStatus (status);
257 public void DrawBeziers (Pen pen, PointF [] points)
260 throw new ArgumentNullException ("pen");
262 throw new ArgumentNullException ("points");
264 int length = points.Length;
270 for (int i = 0; i < length; i += 3) {
271 PointF p1 = points [i];
272 PointF p2 = points [i + 1];
273 PointF p3 = points [i + 2];
274 PointF p4 = points [i + 3];
276 status = GDIPlus.GdipDrawBezier (nativeObject,
278 p1.X, p1.Y, p2.X, p2.Y,
279 p3.X, p3.Y, p4.X, p4.Y);
280 GDIPlus.CheckStatus (status);
285 public void DrawClosedCurve (Pen pen, PointF [] points)
288 throw new ArgumentNullException ("pen");
290 throw new ArgumentNullException ("points");
293 status = GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
294 GDIPlus.CheckStatus (status);
297 public void DrawClosedCurve (Pen pen, Point [] points)
300 throw new ArgumentNullException ("pen");
302 throw new ArgumentNullException ("points");
305 status = GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);
306 GDIPlus.CheckStatus (status);
309 public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode)
312 throw new ArgumentNullException ("pen");
314 throw new ArgumentNullException ("points");
317 status = GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
318 GDIPlus.CheckStatus (status);
321 public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode)
324 throw new ArgumentNullException ("pen");
326 throw new ArgumentNullException ("points");
329 status = GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
330 GDIPlus.CheckStatus (status);
333 public void DrawCurve (Pen pen, Point [] points)
336 throw new ArgumentNullException ("pen");
338 throw new ArgumentNullException ("points");
341 status = GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);
342 GDIPlus.CheckStatus (status);
345 public void DrawCurve (Pen pen, PointF [] points)
348 throw new ArgumentNullException ("pen");
350 throw new ArgumentNullException ("points");
353 status = GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);
354 GDIPlus.CheckStatus (status);
357 public void DrawCurve (Pen pen, PointF [] points, float tension)
360 throw new ArgumentNullException ("pen");
362 throw new ArgumentNullException ("points");
365 status = GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
366 GDIPlus.CheckStatus (status);
369 public void DrawCurve (Pen pen, Point [] points, float tension)
372 throw new ArgumentNullException ("pen");
374 throw new ArgumentNullException ("points");
377 status = GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
378 GDIPlus.CheckStatus (status);
382 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
385 throw new ArgumentNullException ("pen");
387 throw new ArgumentNullException ("points");
390 status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
391 points, points.Length, offset,
392 numberOfSegments, 0.5f);
393 GDIPlus.CheckStatus (status);
396 public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension)
399 throw new ArgumentNullException ("pen");
401 throw new ArgumentNullException ("points");
404 status = GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject,
405 points, points.Length, offset,
406 numberOfSegments, tension);
407 GDIPlus.CheckStatus (status);
411 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
414 throw new ArgumentNullException ("pen");
416 throw new ArgumentNullException ("points");
419 status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
420 points, points.Length, offset,
421 numberOfSegments, tension);
422 GDIPlus.CheckStatus (status);
425 public void DrawEllipse (Pen pen, Rectangle rect)
428 throw new ArgumentNullException ("pen");
430 DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
433 public void DrawEllipse (Pen pen, RectangleF rect)
436 throw new ArgumentNullException ("pen");
437 DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
440 public void DrawEllipse (Pen pen, int x, int y, int width, int height)
443 throw new ArgumentNullException ("pen");
445 status = GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
446 GDIPlus.CheckStatus (status);
449 public void DrawEllipse (Pen pen, float x, float y, float width, float height)
452 throw new ArgumentNullException ("pen");
453 Status status = GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height);
454 GDIPlus.CheckStatus (status);
457 public void DrawIcon (Icon icon, Rectangle targetRect)
459 Image img = icon.ToBitmap ();
460 DrawImage (img, targetRect);
463 public void DrawIcon (Icon icon, int x, int y)
465 Image img = icon.ToBitmap ();
466 DrawImage (img, x, y);
469 public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
471 Image img = icon.ToBitmap ();
472 DrawImageUnscaled (img, targetRect);
475 public void DrawImage (Image image, RectangleF rect)
478 throw new ArgumentNullException ("image");
480 Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y, rect.Width, rect.Height);
481 GDIPlus.CheckStatus (status);
485 public void DrawImage (Image image, PointF point)
488 throw new ArgumentNullException ("image");
490 Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);
491 GDIPlus.CheckStatus (status);
495 public void DrawImage (Image image, Point [] destPoints)
498 throw new ArgumentNullException ("image");
499 if (destPoints == null)
500 throw new ArgumentNullException ("destPoints");
502 Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
503 GDIPlus.CheckStatus (status);
507 public void DrawImage (Image image, Point point)
510 throw new ArgumentNullException ("image");
511 DrawImage (image, point.X, point.Y);
515 public void DrawImage (Image image, Rectangle rect)
518 throw new ArgumentNullException ("image");
519 DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
523 public void DrawImage (Image image, PointF [] destPoints)
526 throw new ArgumentNullException ("image");
527 if (destPoints == null)
528 throw new ArgumentNullException ("destPoints");
529 Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
530 GDIPlus.CheckStatus (status);
534 public void DrawImage (Image image, int x, int y)
537 throw new ArgumentNullException ("image");
538 Status status = GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
539 GDIPlus.CheckStatus (status);
543 public void DrawImage (Image image, float x, float y)
546 throw new ArgumentNullException ("image");
547 Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
548 GDIPlus.CheckStatus (status);
552 public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
555 throw new ArgumentNullException ("image");
556 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
557 destRect.X, destRect.Y, destRect.Width, destRect.Height,
558 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
559 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
560 GDIPlus.CheckStatus (status);
563 public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
566 throw new ArgumentNullException ("image");
567 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
568 destRect.X, destRect.Y, destRect.Width, destRect.Height,
569 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
570 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
571 GDIPlus.CheckStatus (status);
575 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
578 throw new ArgumentNullException ("image");
579 if (destPoints == null)
580 throw new ArgumentNullException ("destPoints");
582 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
583 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
584 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
586 GDIPlus.CheckStatus (status);
590 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
593 throw new ArgumentNullException ("image");
594 if (destPoints == null)
595 throw new ArgumentNullException ("destPoints");
597 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
598 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
599 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
601 GDIPlus.CheckStatus (status);
605 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit,
606 ImageAttributes imageAttr)
609 throw new ArgumentNullException ("image");
610 if (destPoints == null)
611 throw new ArgumentNullException ("destPoints");
612 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
613 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
614 srcRect.Width, srcRect.Height, srcUnit,
615 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
616 GDIPlus.CheckStatus (status);
619 public void DrawImage (Image image, float x, float y, float width, float height)
622 throw new ArgumentNullException ("image");
623 Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
625 GDIPlus.CheckStatus (status);
629 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit,
630 ImageAttributes imageAttr)
633 throw new ArgumentNullException ("image");
634 if (destPoints == null)
635 throw new ArgumentNullException ("destPoints");
636 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
637 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
638 srcRect.Width, srcRect.Height, srcUnit,
639 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
640 GDIPlus.CheckStatus (status);
644 public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
647 throw new ArgumentNullException ("image");
648 Status status = GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
649 GDIPlus.CheckStatus (status);
652 public void DrawImage (Image image, int x, int y, int width, int height)
655 throw new ArgumentNullException ("image");
656 Status status = GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
657 GDIPlus.CheckStatus (status);
660 public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
663 throw new ArgumentNullException ("image");
664 Status status = GDIPlus.GdipDrawImagePointRect (nativeObject, image.nativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
665 GDIPlus.CheckStatus (status);
669 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
672 throw new ArgumentNullException ("image");
673 if (destPoints == null)
674 throw new ArgumentNullException ("destPoints");
675 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
676 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
677 srcRect.Width, srcRect.Height, srcUnit,
678 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
679 GDIPlus.CheckStatus (status);
683 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
686 throw new ArgumentNullException ("image");
687 if (destPoints == null)
688 throw new ArgumentNullException ("destPoints");
690 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
691 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
692 srcRect.Width, srcRect.Height, srcUnit,
693 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
694 GDIPlus.CheckStatus (status);
698 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
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,
708 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
709 GDIPlus.CheckStatus (status);
713 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
716 throw new ArgumentNullException ("image");
717 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
718 destRect.X, destRect.Y, destRect.Width, destRect.Height,
719 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero,
721 GDIPlus.CheckStatus (status);
724 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
726 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
727 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
728 srcRect.Width, srcRect.Height, srcUnit,
729 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
730 GDIPlus.CheckStatus (status);
734 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
737 throw new ArgumentNullException ("image");
738 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
739 destRect.X, destRect.Y, destRect.Width, destRect.Height,
740 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero,
742 GDIPlus.CheckStatus (status);
746 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
749 throw new ArgumentNullException ("image");
750 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
751 destRect.X, destRect.Y, destRect.Width, destRect.Height,
752 srcX, srcY, srcWidth, srcHeight, srcUnit,
753 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
754 GDIPlus.CheckStatus (status);
757 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
760 throw new ArgumentNullException ("image");
761 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
762 destRect.X, destRect.Y, destRect.Width,
763 destRect.Height, srcX, srcY, srcWidth, srcHeight,
764 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
765 GDIPlus.CheckStatus (status);
768 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
771 throw new ArgumentNullException ("image");
772 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
773 destRect.X, destRect.Y, destRect.Width,
774 destRect.Height, srcX, srcY, srcWidth, srcHeight,
775 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback,
777 GDIPlus.CheckStatus (status);
780 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
783 throw new ArgumentNullException ("image");
784 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
785 destRect.X, destRect.Y, destRect.Width,
786 destRect.Height, srcX, srcY, srcWidth, srcHeight,
787 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero,
788 callback, IntPtr.Zero);
789 GDIPlus.CheckStatus (status);
793 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
796 throw new ArgumentNullException ("image");
797 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
798 destRect.X, destRect.Y, destRect.Width, destRect.Height,
799 srcX, srcY, srcWidth, srcHeight, srcUnit,
800 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, callbackData);
801 GDIPlus.CheckStatus (status);
805 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
808 throw new ArgumentNullException ("image");
809 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
810 destRect.X, destRect.Y, destRect.Width, destRect.Height,
811 srcX, srcY, srcWidth, srcHeight, srcUnit,
812 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, callbackData);
813 GDIPlus.CheckStatus (status);
816 public void DrawImageUnscaled (Image image, Point point)
819 throw new ArgumentNullException ("image");
820 DrawImageUnscaled (image, point.X, point.Y);
823 public void DrawImageUnscaled (Image image, Rectangle rect)
826 throw new ArgumentNullException ("image");
827 DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
830 public void DrawImageUnscaled (Image image, int x, int y)
833 throw new ArgumentNullException ("image");
834 DrawImage (image, x, y, image.Width, image.Height);
837 public void DrawImageUnscaled (Image image, int x, int y, int width, int height)
840 throw new ArgumentNullException ("image");
841 Image tmpImg = new Bitmap (width, height);
842 Graphics g = FromImage (tmpImg);
843 g.DrawImage (image, 0, 0, image.Width, image.Height);
844 this.DrawImage (tmpImg, x, y, width, height);
849 public void DrawLine (Pen pen, PointF pt1, PointF pt2)
852 throw new ArgumentNullException ("pen");
853 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject,
854 pt1.X, pt1.Y, pt2.X, pt2.Y);
855 GDIPlus.CheckStatus (status);
858 public void DrawLine (Pen pen, Point pt1, Point pt2)
861 throw new ArgumentNullException ("pen");
862 Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject,
863 pt1.X, pt1.Y, pt2.X, pt2.Y);
864 GDIPlus.CheckStatus (status);
867 public void DrawLine (Pen pen, int x1, int y1, int x2, int y2)
870 throw new ArgumentNullException ("pen");
871 Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);
872 GDIPlus.CheckStatus (status);
875 public void DrawLine (Pen pen, float x1, float y1, float x2, float y2)
878 throw new ArgumentNullException ("pen");
879 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);
880 GDIPlus.CheckStatus (status);
883 public void DrawLines (Pen pen, PointF [] points)
886 throw new ArgumentNullException ("pen");
888 throw new ArgumentNullException ("points");
889 Status status = GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);
890 GDIPlus.CheckStatus (status);
893 public void DrawLines (Pen pen, Point [] points)
896 throw new ArgumentNullException ("pen");
898 throw new ArgumentNullException ("points");
899 Status status = GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);
900 GDIPlus.CheckStatus (status);
903 public void DrawPath (Pen pen, GraphicsPath path)
906 throw new ArgumentNullException ("pen");
908 throw new ArgumentNullException ("path");
909 Status status = GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
910 GDIPlus.CheckStatus (status);
913 public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
916 throw new ArgumentNullException ("pen");
917 DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
920 public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
923 throw new ArgumentNullException ("pen");
924 DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
927 public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
930 throw new ArgumentNullException ("pen");
931 Status status = GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
932 GDIPlus.CheckStatus (status);
935 // Microsoft documentation states that the signature for this member should be
936 // public void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle
937 // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
938 public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
941 throw new ArgumentNullException ("pen");
942 Status status = GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
943 GDIPlus.CheckStatus (status);
946 public void DrawPolygon (Pen pen, Point [] points)
949 throw new ArgumentNullException ("pen");
951 throw new ArgumentNullException ("points");
952 Status status = GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
953 GDIPlus.CheckStatus (status);
956 public void DrawPolygon (Pen pen, PointF [] points)
959 throw new ArgumentNullException ("pen");
961 throw new ArgumentNullException ("points");
962 Status status = GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
963 GDIPlus.CheckStatus (status);
966 internal void DrawRectangle (Pen pen, RectangleF rect)
969 throw new ArgumentNullException ("pen");
970 DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
973 public void DrawRectangle (Pen pen, Rectangle rect)
976 throw new ArgumentNullException ("pen");
977 DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
980 public void DrawRectangle (Pen pen, float x, float y, float width, float height)
983 throw new ArgumentNullException ("pen");
984 Status status = GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
985 GDIPlus.CheckStatus (status);
988 public void DrawRectangle (Pen pen, int x, int y, int width, int height)
991 throw new ArgumentNullException ("pen");
992 Status status = GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
993 GDIPlus.CheckStatus (status);
996 public void DrawRectangles (Pen pen, RectangleF [] rects)
999 throw new ArgumentNullException ("image");
1001 throw new ArgumentNullException ("rects");
1002 Status status = GDIPlus.GdipDrawRectangles (nativeObject, pen.nativeObject, rects, rects.Length);
1003 GDIPlus.CheckStatus (status);
1006 public void DrawRectangles (Pen pen, Rectangle [] rects)
1009 throw new ArgumentNullException ("image");
1011 throw new ArgumentNullException ("rects");
1012 Status status = GDIPlus.GdipDrawRectanglesI (nativeObject, pen.nativeObject, rects, rects.Length);
1013 GDIPlus.CheckStatus (status);
1016 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle)
1018 DrawString (s, font, brush, layoutRectangle, null);
1021 public void DrawString (string s, Font font, Brush brush, PointF point)
1023 DrawString (s, font, brush, new RectangleF (point.X, point.Y, 0, 0), null);
1026 public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format)
1028 DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
1031 public void DrawString (string s, Font font, Brush brush, float x, float y)
1033 DrawString (s, font, brush, new RectangleF (x, y, 0, 0), null);
1036 public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format)
1038 DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
1041 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
1044 throw new ArgumentNullException ("font");
1046 throw new ArgumentNullException ("brush");
1047 if (s == null || s.Length == 0)
1050 Status status = GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, format != null ? format.NativeObject : IntPtr.Zero, brush.nativeObject);
1051 GDIPlus.CheckStatus (status);
1054 public void EndContainer (GraphicsContainer container)
1056 if (container == null)
1057 throw new ArgumentNullException ("container");
1058 Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
1059 GDIPlus.CheckStatus (status);
1063 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
1065 throw new NotImplementedException ();
1069 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
1071 throw new NotImplementedException ();
1075 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
1077 throw new NotImplementedException ();
1081 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
1083 throw new NotImplementedException ();
1087 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
1089 throw new NotImplementedException ();
1093 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
1095 throw new NotImplementedException ();
1099 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1101 throw new NotImplementedException ();
1105 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1107 throw new NotImplementedException ();
1111 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1113 throw new NotImplementedException ();
1117 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1119 throw new NotImplementedException ();
1123 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1125 throw new NotImplementedException ();
1129 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1131 throw new NotImplementedException ();
1135 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1137 throw new NotImplementedException ();
1141 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1143 throw new NotImplementedException ();
1147 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1149 throw new NotImplementedException ();
1153 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1155 throw new NotImplementedException ();
1159 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1161 throw new NotImplementedException ();
1165 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1167 throw new NotImplementedException ();
1171 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1173 throw new NotImplementedException ();
1177 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1179 throw new NotImplementedException ();
1183 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1185 throw new NotImplementedException ();
1189 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1191 throw new NotImplementedException ();
1195 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1197 throw new NotImplementedException ();
1201 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1203 throw new NotImplementedException ();
1207 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1209 throw new NotImplementedException ();
1213 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1215 throw new NotImplementedException ();
1219 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1221 throw new NotImplementedException ();
1225 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1227 throw new NotImplementedException ();
1231 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1233 throw new NotImplementedException ();
1237 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1239 throw new NotImplementedException ();
1243 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1245 throw new NotImplementedException ();
1249 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1251 throw new NotImplementedException ();
1255 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1257 throw new NotImplementedException ();
1261 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1263 throw new NotImplementedException ();
1267 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1269 throw new NotImplementedException ();
1273 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1275 throw new NotImplementedException ();
1278 public void ExcludeClip (Rectangle rect)
1280 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);
1281 GDIPlus.CheckStatus (status);
1284 public void ExcludeClip (Region region)
1287 throw new ArgumentNullException ("region");
1288 Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Exclude);
1289 GDIPlus.CheckStatus (status);
1293 public void FillClosedCurve (Brush brush, PointF [] points)
1296 throw new ArgumentNullException ("brush");
1298 throw new ArgumentNullException ("points");
1299 Status status = GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
1300 GDIPlus.CheckStatus (status);
1304 public void FillClosedCurve (Brush brush, Point [] points)
1307 throw new ArgumentNullException ("brush");
1309 throw new ArgumentNullException ("points");
1310 Status status = GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
1311 GDIPlus.CheckStatus (status);
1315 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode)
1318 throw new ArgumentNullException ("brush");
1320 throw new ArgumentNullException ("points");
1321 FillClosedCurve (brush, points, fillmode, 0.5f);
1324 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode)
1327 throw new ArgumentNullException ("brush");
1329 throw new ArgumentNullException ("points");
1330 FillClosedCurve (brush, points, fillmode, 0.5f);
1333 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension)
1336 throw new ArgumentNullException ("brush");
1338 throw new ArgumentNullException ("points");
1339 Status status = GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1340 GDIPlus.CheckStatus (status);
1343 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension)
1346 throw new ArgumentNullException ("brush");
1348 throw new ArgumentNullException ("points");
1349 Status status = GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1350 GDIPlus.CheckStatus (status);
1353 public void FillEllipse (Brush brush, Rectangle rect)
1356 throw new ArgumentNullException ("brush");
1357 FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1360 public void FillEllipse (Brush brush, RectangleF rect)
1363 throw new ArgumentNullException ("brush");
1364 FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1367 public void FillEllipse (Brush brush, float x, float y, float width, float height)
1370 throw new ArgumentNullException ("brush");
1371 Status status = GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
1372 GDIPlus.CheckStatus (status);
1375 public void FillEllipse (Brush brush, int x, int y, int width, int height)
1378 throw new ArgumentNullException ("brush");
1379 Status status = GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
1380 GDIPlus.CheckStatus (status);
1383 public void FillPath (Brush brush, GraphicsPath path)
1386 throw new ArgumentNullException ("brush");
1388 throw new ArgumentNullException ("path");
1389 Status status = GDIPlus.GdipFillPath (nativeObject, brush.NativeObject, path.NativeObject);
1390 GDIPlus.CheckStatus (status);
1393 public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)
1396 throw new ArgumentNullException ("brush");
1397 Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1398 GDIPlus.CheckStatus (status);
1401 public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
1404 throw new ArgumentNullException ("brush");
1405 Status status = GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1406 GDIPlus.CheckStatus (status);
1409 public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
1412 throw new ArgumentNullException ("brush");
1413 Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1414 GDIPlus.CheckStatus (status);
1417 public void FillPolygon (Brush brush, PointF [] points)
1420 throw new ArgumentNullException ("brush");
1422 throw new ArgumentNullException ("points");
1423 Status status = GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
1424 GDIPlus.CheckStatus (status);
1427 public void FillPolygon (Brush brush, Point [] points)
1430 throw new ArgumentNullException ("brush");
1432 throw new ArgumentNullException ("points");
1433 Status status = GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
1434 GDIPlus.CheckStatus (status);
1437 public void FillPolygon (Brush brush, Point [] points, FillMode fillMode)
1440 throw new ArgumentNullException ("brush");
1442 throw new ArgumentNullException ("points");
1443 Status status = GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1444 GDIPlus.CheckStatus (status);
1447 public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode)
1450 throw new ArgumentNullException ("brush");
1452 throw new ArgumentNullException ("points");
1453 Status status = GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1454 GDIPlus.CheckStatus (status);
1457 public void FillRectangle (Brush brush, RectangleF rect)
1460 throw new ArgumentNullException ("brush");
1461 FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1464 public void FillRectangle (Brush brush, Rectangle rect)
1467 throw new ArgumentNullException ("brush");
1468 FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1471 public void FillRectangle (Brush brush, int x, int y, int width, int height)
1474 throw new ArgumentNullException ("brush");
1476 Status status = GDIPlus.GdipFillRectangleI (nativeObject, brush.nativeObject, x, y, width, height);
1477 GDIPlus.CheckStatus (status);
1480 public void FillRectangle (Brush brush, float x, float y, float width, float height)
1483 throw new ArgumentNullException ("brush");
1485 Status status = GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
1486 GDIPlus.CheckStatus (status);
1489 public void FillRectangles (Brush brush, Rectangle [] rects)
1492 throw new ArgumentNullException ("brush");
1494 Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
1495 GDIPlus.CheckStatus (status);
1498 public void FillRectangles (Brush brush, RectangleF [] rects)
1501 throw new ArgumentNullException ("brush");
1503 Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
1504 GDIPlus.CheckStatus (status);
1508 public void FillRegion (Brush brush, Region region)
1511 throw new ArgumentNullException ("brush");
1513 throw new ArgumentNullException ("region");
1515 Status status = GDIPlus.GdipFillRegion (nativeObject, brush.NativeObject, region.NativeObject);
1516 GDIPlus.CheckStatus(status);
1520 public void Flush ()
1522 Flush (FlushIntention.Flush);
1526 public void Flush (FlushIntention intention)
1528 Status status = GDIPlus.GdipFlush (nativeObject, intention);
1529 GDIPlus.CheckStatus (status);
1530 if (GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable)
1531 Carbon.CGContextSynchronize (GDIPlus.Display);
1534 [EditorBrowsable (EditorBrowsableState.Advanced)]
1535 public static Graphics FromHdc (IntPtr hdc)
1538 Status status = GDIPlus.GdipCreateFromHDC (hdc, out graphics);
1539 GDIPlus.CheckStatus (status);
1540 return new Graphics (graphics);
1544 [EditorBrowsable (EditorBrowsableState.Advanced)]
1545 public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
1547 throw new NotImplementedException ();
1550 [EditorBrowsable (EditorBrowsableState.Advanced)]
1551 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1552 public static Graphics FromHdcInternal (IntPtr hdc)
1554 GDIPlus.Display = hdc;
1558 [EditorBrowsable (EditorBrowsableState.Advanced)]
1559 public static Graphics FromHwnd (IntPtr hwnd)
1563 if (GDIPlus.UseCocoaDrawable) {
1564 CarbonContext cgContext = Carbon.GetCGContextForNSView (hwnd);
1565 GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
1567 GDIPlus.Display = cgContext.ctx;
1568 return new Graphics (graphics);
1570 if (GDIPlus.UseQuartzDrawable) {
1571 CarbonContext cgContext = Carbon.GetCGContextForView (hwnd);
1572 GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
1574 GDIPlus.Display = cgContext.ctx;
1575 return new Graphics (graphics);
1577 if (GDIPlus.UseX11Drawable) {
1578 if (GDIPlus.Display == IntPtr.Zero) {
1579 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
1582 return FromXDrawable (hwnd, GDIPlus.Display);
1586 Status status = GDIPlus.GdipCreateFromHWND (hwnd, out graphics);
1587 GDIPlus.CheckStatus (status);
1589 return new Graphics (graphics);
1592 [EditorBrowsable (EditorBrowsableState.Advanced)]
1593 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1594 public static Graphics FromHwndInternal (IntPtr hwnd)
1596 return FromHwnd (hwnd);
1599 public static Graphics FromImage (Image image)
1604 throw new ArgumentNullException ("image");
1606 Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
1607 GDIPlus.CheckStatus (status);
1608 Graphics result = new Graphics (graphics);
1610 // check for Unix platforms - see FAQ for more details
1611 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1612 int platform = (int) Environment.OSVersion.Platform;
1613 if ((platform == 4) || (platform == 128)) {
1614 Rectangle rect = new Rectangle (0,0, image.Width, image.Height);
1615 GDIPlus.GdipSetVisibleClip_linux (result.NativeObject, ref rect);
1621 internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
1625 Status s = GDIPlus.GdipCreateFromXDrawable_linux (drawable, display, out graphics);
1626 GDIPlus.CheckStatus (s);
1627 return new Graphics (graphics);
1631 public static IntPtr GetHalftonePalette ()
1633 throw new NotImplementedException ();
1636 [EditorBrowsable (EditorBrowsableState.Advanced)]
1637 public IntPtr GetHdc ()
1640 GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out hdc));
1645 public Color GetNearestColor (Color color)
1649 Status status = GDIPlus.GdipGetNearestColor (nativeObject, out argb);
1650 GDIPlus.CheckStatus (status);
1652 return Color.FromArgb (argb);
1656 public void IntersectClip (Region region)
1659 throw new ArgumentNullException ("region");
1660 Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Intersect);
1661 GDIPlus.CheckStatus (status);
1664 public void IntersectClip (RectangleF rect)
1666 Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1667 GDIPlus.CheckStatus (status);
1670 public void IntersectClip (Rectangle rect)
1672 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1673 GDIPlus.CheckStatus (status);
1676 public bool IsVisible (Point point)
1678 bool isVisible = false;
1680 Status status = GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
1681 GDIPlus.CheckStatus (status);
1687 public bool IsVisible (RectangleF rect)
1689 bool isVisible = false;
1691 Status status = GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1692 GDIPlus.CheckStatus (status);
1697 public bool IsVisible (PointF point)
1699 bool isVisible = false;
1701 Status status = GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
1702 GDIPlus.CheckStatus (status);
1707 public bool IsVisible (Rectangle rect)
1709 bool isVisible = false;
1711 Status status = GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1712 GDIPlus.CheckStatus (status);
1717 public bool IsVisible (float x, float y)
1719 return IsVisible (new PointF (x, y));
1722 public bool IsVisible (int x, int y)
1724 return IsVisible (new Point (x, y));
1727 public bool IsVisible (float x, float y, float width, float height)
1729 return IsVisible (new RectangleF (x, y, width, height));
1733 public bool IsVisible (int x, int y, int width, int height)
1735 return IsVisible (new Rectangle (x, y, width, height));
1739 public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
1742 int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
1743 IntPtr[] native_regions = new IntPtr [regcount];
1744 Region[] regions = new Region [regcount];
1746 for (int i = 0; i < regcount; i++) {
1747 regions[i] = new Region ();
1748 native_regions[i] = regions[i].NativeObject;
1751 status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
1752 font.NativeObject, ref layoutRect, stringFormat.NativeObject,
1753 regcount, out native_regions[0]);
1755 GDIPlus.CheckStatus (status);
1761 public SizeF MeasureString (string text, Font font)
1763 return MeasureString (text, font, new Size (0, 0));
1767 public SizeF MeasureString (string text, Font font, SizeF layoutArea)
1769 int charactersFitted, linesFilled;
1770 RectangleF boundingBox = new RectangleF ();
1771 RectangleF rect = new RectangleF (0, 0, layoutArea.Width,
1774 if (text == null || text.Length == 0)
1778 throw new ArgumentNullException ("font");
1780 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
1781 font.NativeObject, ref rect,
1782 IntPtr.Zero, out boundingBox,
1783 out charactersFitted, out linesFilled);
1784 GDIPlus.CheckStatus (status);
1786 return new SizeF (boundingBox.Width, boundingBox.Height);
1790 public SizeF MeasureString (string text, Font font, int width)
1792 RectangleF boundingBox = new RectangleF ();
1793 RectangleF rect = new RectangleF (0, 0, width, 999999);
1794 int charactersFitted, linesFilled;
1796 if (text == null || text.Length == 0)
1800 throw new ArgumentNullException ("font");
1802 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
1803 font.NativeObject, ref rect,
1804 IntPtr.Zero, out boundingBox,
1805 out charactersFitted, out linesFilled);
1806 GDIPlus.CheckStatus (status);
1808 return new SizeF (boundingBox.Width, boundingBox.Height);
1812 public SizeF MeasureString (string text, Font font, SizeF layoutArea,
1813 StringFormat stringFormat)
1815 int charactersFitted, linesFilled;
1816 return MeasureString (text, font, layoutArea, stringFormat,
1817 out charactersFitted, out linesFilled);
1821 public SizeF MeasureString (string text, Font font, int width, StringFormat format)
1823 int charactersFitted, linesFilled;
1824 return MeasureString (text, font, new SizeF (width, 999999),
1825 format, out charactersFitted, out linesFilled);
1829 public SizeF MeasureString (string text, Font font, PointF origin,
1830 StringFormat stringFormat)
1832 RectangleF boundingBox = new RectangleF ();
1833 RectangleF rect = new RectangleF (origin.X, origin.Y, 0, 0);
1834 int charactersFitted, linesFilled;
1836 if (text == null || text.Length == 0)
1840 throw new ArgumentNullException ("font");
1842 if (stringFormat == null)
1843 stringFormat = new StringFormat ();
1845 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
1846 font.NativeObject, ref rect,
1847 stringFormat.NativeObject,
1849 out charactersFitted,
1851 GDIPlus.CheckStatus (status);
1853 return new SizeF (boundingBox.Width, boundingBox.Height);
1857 public SizeF MeasureString (string text, Font font, SizeF layoutArea,
1858 StringFormat stringFormat, out int charactersFitted,
1859 out int linesFilled)
1861 RectangleF boundingBox = new RectangleF ();
1862 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1863 charactersFitted = 0;
1866 if (text == null || text.Length == 0)
1870 throw new ArgumentNullException ("font");
1872 if (stringFormat == null)
1873 stringFormat = new StringFormat ();
1875 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
1876 font.NativeObject, ref rect,
1877 stringFormat.NativeObject,
1879 out charactersFitted,
1881 GDIPlus.CheckStatus (status);
1883 return new SizeF (boundingBox.Width, boundingBox.Height);
1886 public void MultiplyTransform (Matrix matrix)
1888 MultiplyTransform (matrix, MatrixOrder.Prepend);
1891 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
1893 Status status = GDIPlus.GdipMultiplyWorldTransform (nativeObject,
1894 matrix.nativeMatrix,
1896 GDIPlus.CheckStatus (status);
1899 [EditorBrowsable (EditorBrowsableState.Advanced)]
1900 public void ReleaseHdc (IntPtr hdc)
1902 Status status = GDIPlus.GdipReleaseDC (nativeObject, hdc);
1903 GDIPlus.CheckStatus (status);
1907 [EditorBrowsable (EditorBrowsableState.Advanced)]
1908 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1909 public void ReleaseHdcInternal (IntPtr hdc)
1911 throw new NotImplementedException ();
1915 public void ResetClip ()
1917 Status status = GDIPlus.GdipResetClip (nativeObject);
1918 GDIPlus.CheckStatus (status);
1921 public void ResetTransform ()
1923 Status status = GDIPlus.GdipResetWorldTransform (nativeObject);
1924 GDIPlus.CheckStatus (status);
1927 public void Restore (GraphicsState gstate)
1929 Status status = GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
1930 GDIPlus.CheckStatus (status);
1934 public void RotateTransform (float angle)
1936 RotateTransform (angle, MatrixOrder.Prepend);
1939 public void RotateTransform (float angle, MatrixOrder order)
1942 Status status = GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
1943 GDIPlus.CheckStatus (status);
1946 public GraphicsState Save ()
1949 Status status = GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
1950 GDIPlus.CheckStatus (status);
1952 GraphicsState state = new GraphicsState ();
1953 state.nativeState = saveState;
1957 public void ScaleTransform (float sx, float sy)
1959 ScaleTransform (sx, sy, MatrixOrder.Prepend);
1962 public void ScaleTransform (float sx, float sy, MatrixOrder order)
1964 Status status = GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
1965 GDIPlus.CheckStatus (status);
1969 public void SetClip (RectangleF rect)
1971 SetClip (rect, CombineMode.Replace);
1975 public void SetClip (GraphicsPath path)
1977 SetClip (path, CombineMode.Replace);
1981 public void SetClip (Rectangle rect)
1983 SetClip (rect, CombineMode.Replace);
1987 public void SetClip (Graphics g)
1989 SetClip (g, CombineMode.Replace);
1993 public void SetClip (Graphics g, CombineMode combineMode)
1996 throw new ArgumentNullException ("g");
1998 Status status = GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
1999 GDIPlus.CheckStatus (status);
2003 public void SetClip (Rectangle rect, CombineMode combineMode)
2005 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2006 GDIPlus.CheckStatus (status);
2010 public void SetClip (RectangleF rect, CombineMode combineMode)
2012 Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2013 GDIPlus.CheckStatus (status);
2017 public void SetClip (Region region, CombineMode combineMode)
2020 throw new ArgumentNullException ("region");
2021 Status status = GDIPlus.GdipSetClipRegion(nativeObject, region.NativeObject, combineMode);
2022 GDIPlus.CheckStatus (status);
2026 public void SetClip (GraphicsPath path, CombineMode combineMode)
2029 throw new ArgumentNullException ("path");
2030 Status status = GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
2031 GDIPlus.CheckStatus (status);
2035 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts)
2038 throw new ArgumentNullException ("pts");
2040 IntPtr ptrPt = GDIPlus.FromPointToUnManagedMemory (pts);
2042 Status status = GDIPlus.GdipTransformPoints (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2043 GDIPlus.CheckStatus (status);
2045 GDIPlus.FromUnManagedMemoryToPoint (ptrPt, pts);
2049 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
2052 throw new ArgumentNullException ("pts");
2053 IntPtr ptrPt = GDIPlus.FromPointToUnManagedMemoryI (pts);
2055 Status status = GDIPlus.GdipTransformPointsI (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2056 GDIPlus.CheckStatus (status);
2058 GDIPlus.FromUnManagedMemoryToPointI (ptrPt, pts);
2062 public void TranslateClip (int dx, int dy)
2064 Status status = GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);
2065 GDIPlus.CheckStatus (status);
2069 public void TranslateClip (float dx, float dy)
2071 Status status = GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
2072 GDIPlus.CheckStatus (status);
2075 public void TranslateTransform (float dx, float dy)
2077 TranslateTransform (dx, dy, MatrixOrder.Prepend);
2081 public void TranslateTransform (float dx, float dy, MatrixOrder order)
2083 Status status = GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
2084 GDIPlus.CheckStatus (status);
2087 public Region Clip {
2089 Region reg = new Region();
2090 Status status = GDIPlus.GdipGetClip (nativeObject, reg.NativeObject);
2091 GDIPlus.CheckStatus (status);
2095 SetClip (value, CombineMode.Replace);
2099 public RectangleF ClipBounds {
2101 RectangleF rect = new RectangleF ();
2102 Status status = GDIPlus.GdipGetClipBounds (nativeObject, out rect);
2103 GDIPlus.CheckStatus (status);
2108 public CompositingMode CompositingMode {
2110 CompositingMode mode;
2111 Status status = GDIPlus.GdipGetCompositingMode (nativeObject, out mode);
2112 GDIPlus.CheckStatus (status);
2117 Status status = GDIPlus.GdipSetCompositingMode (nativeObject, value);
2118 GDIPlus.CheckStatus (status);
2123 public CompositingQuality CompositingQuality {
2125 CompositingQuality quality;
2127 Status status = GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
2128 GDIPlus.CheckStatus (status);
2132 Status status = GDIPlus.GdipSetCompositingQuality (nativeObject, value);
2133 GDIPlus.CheckStatus (status);
2141 Status status = GDIPlus.GdipGetDpiX (nativeObject, out x);
2142 GDIPlus.CheckStatus (status);
2151 Status status = GDIPlus.GdipGetDpiY (nativeObject, out y);
2152 GDIPlus.CheckStatus (status);
2157 public InterpolationMode InterpolationMode {
2159 InterpolationMode imode = InterpolationMode.Invalid;
2160 Status status = GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
2161 GDIPlus.CheckStatus (status);
2165 Status status = GDIPlus.GdipSetInterpolationMode (nativeObject, value);
2166 GDIPlus.CheckStatus (status);
2170 public bool IsClipEmpty {
2172 bool isEmpty = false;
2174 Status status = GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
2175 GDIPlus.CheckStatus (status);
2180 public bool IsVisibleClipEmpty {
2182 bool isEmpty = false;
2184 Status status = GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
2185 GDIPlus.CheckStatus (status);
2190 public float PageScale {
2194 Status status = GDIPlus.GdipGetPageScale (nativeObject, out scale);
2195 GDIPlus.CheckStatus (status);
2199 Status status = GDIPlus.GdipSetPageScale (nativeObject, value);
2200 GDIPlus.CheckStatus (status);
2204 public GraphicsUnit PageUnit {
2208 Status status = GDIPlus.GdipGetPageUnit (nativeObject, out unit);
2209 GDIPlus.CheckStatus (status);
2213 Status status = GDIPlus.GdipSetPageUnit (nativeObject, value);
2214 GDIPlus.CheckStatus (status);
2218 public PixelOffsetMode PixelOffsetMode {
2220 PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
2222 Status status = GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
2223 GDIPlus.CheckStatus (status);
2227 Status status = GDIPlus.GdipSetPixelOffsetMode (nativeObject, value);
2228 GDIPlus.CheckStatus (status);
2232 public Point RenderingOrigin {
2235 Status status = GDIPlus.GdipGetRenderingOrigin (nativeObject, out x, out y);
2236 GDIPlus.CheckStatus (status);
2237 return new Point (x, y);
2241 Status status = GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
2242 GDIPlus.CheckStatus (status);
2246 public SmoothingMode SmoothingMode {
2248 SmoothingMode mode = SmoothingMode.Invalid;
2250 Status status = GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
2251 GDIPlus.CheckStatus (status);
2256 Status status = GDIPlus.GdipSetSmoothingMode (nativeObject, value);
2257 GDIPlus.CheckStatus (status);
2261 public int TextContrast {
2265 Status status = GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
2266 GDIPlus.CheckStatus (status);
2271 Status status = GDIPlus.GdipSetTextContrast (nativeObject, value);
2272 GDIPlus.CheckStatus (status);
2276 public TextRenderingHint TextRenderingHint {
2278 TextRenderingHint hint;
2280 Status status = GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
2281 GDIPlus.CheckStatus (status);
2286 Status status = GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
2287 GDIPlus.CheckStatus (status);
2291 public Matrix Transform {
2293 Matrix matrix = new Matrix ();
2294 Status status = GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
2295 GDIPlus.CheckStatus (status);
2300 throw new ArgumentNullException ("value");
2302 Status status = GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
2303 GDIPlus.CheckStatus (status);
2307 public RectangleF VisibleClipBounds {
2311 Status status = GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
2312 GDIPlus.CheckStatus (status);