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
;
40 namespace System
.Drawing
42 public sealed class Graphics
: MarshalByRefObject
, IDisposable
45 internal IntPtr nativeObject
= IntPtr
.Zero
;
46 internal IMacContext maccontext
;
47 private bool disposed
= false;
48 private static float defDpiX
= 0;
49 private static float defDpiY
= 0;
50 private IntPtr deviceContextHdc
;
51 private Metafile
.MetafileHolder _metafileHolder
;
53 public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType
,
57 PlayRecordCallback callbackData
);
59 public delegate bool DrawImageAbort (IntPtr callbackdata
);
61 internal Graphics (IntPtr nativeGraphics
)
63 nativeObject
= nativeGraphics
;
66 internal Graphics(IntPtr nativeGraphics
, Image image
) : this(nativeGraphics
)
68 if (image
is Metafile mf
) {
69 _metafileHolder
= mf
.AddMetafileHolder();
78 static internal float systemDpiX
{
81 Bitmap bmp
= new Bitmap (1, 1);
82 Graphics g
= Graphics
.FromImage (bmp
);
90 static internal float systemDpiY
{
93 Bitmap bmp
= new Bitmap (1, 1);
94 Graphics g
= Graphics
.FromImage (bmp
);
102 // For CoreFX compatibility
103 internal IntPtr NativeGraphics
{
109 internal IntPtr NativeObject
{
115 nativeObject
= value;
119 [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
120 public void AddMetafileComment (byte [] data
)
122 throw new NotImplementedException ();
125 public GraphicsContainer
BeginContainer ()
129 status
= GDIPlus
.GdipBeginContainer2 (nativeObject
, out state
);
130 GDIPlus
.CheckStatus (status
);
132 return new GraphicsContainer(state
);
135 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]
136 public GraphicsContainer
BeginContainer (Rectangle dstrect
, Rectangle srcrect
, GraphicsUnit unit
)
140 status
= GDIPlus
.GdipBeginContainerI (nativeObject
, ref dstrect
, ref srcrect
, unit
, out state
);
141 GDIPlus
.CheckStatus (status
);
143 return new GraphicsContainer (state
);
146 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]
147 public GraphicsContainer
BeginContainer (RectangleF dstrect
, RectangleF srcrect
, GraphicsUnit unit
)
151 status
= GDIPlus
.GdipBeginContainer (nativeObject
, ref dstrect
, ref srcrect
, unit
, out state
);
152 GDIPlus
.CheckStatus (status
);
154 return new GraphicsContainer (state
);
158 public void Clear (Color color
)
161 status
= GDIPlus
.GdipGraphicsClear (nativeObject
, color
.ToArgb ());
162 GDIPlus
.CheckStatus (status
);
164 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
165 public void CopyFromScreen (Point upperLeftSource
, Point upperLeftDestination
, Size blockRegionSize
)
167 CopyFromScreen (upperLeftSource
.X
, upperLeftSource
.Y
, upperLeftDestination
.X
, upperLeftDestination
.Y
,
168 blockRegionSize
, CopyPixelOperation
.SourceCopy
);
171 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
172 public void CopyFromScreen (Point upperLeftSource
, Point upperLeftDestination
, Size blockRegionSize
, CopyPixelOperation copyPixelOperation
)
174 CopyFromScreen (upperLeftSource
.X
, upperLeftSource
.Y
, upperLeftDestination
.X
, upperLeftDestination
.Y
,
175 blockRegionSize
, copyPixelOperation
);
178 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
179 public void CopyFromScreen (int sourceX
, int sourceY
, int destinationX
, int destinationY
, Size blockRegionSize
)
181 CopyFromScreen (sourceX
, sourceY
, destinationX
, destinationY
, blockRegionSize
,
182 CopyPixelOperation
.SourceCopy
);
185 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
186 public void CopyFromScreen (int sourceX
, int sourceY
, int destinationX
, int destinationY
, Size blockRegionSize
, CopyPixelOperation copyPixelOperation
)
188 if (!Enum
.IsDefined (typeof (CopyPixelOperation
), copyPixelOperation
))
189 throw new InvalidEnumArgumentException (Locale
.GetText ("Enum argument value '{0}' is not valid for CopyPixelOperation", copyPixelOperation
));
191 if (GDIPlus
.UseX11Drawable
) {
192 CopyFromScreenX11 (sourceX
, sourceY
, destinationX
, destinationY
, blockRegionSize
, copyPixelOperation
);
193 } else if (GDIPlus
.UseCarbonDrawable
) {
194 CopyFromScreenMac (sourceX
, sourceY
, destinationX
, destinationY
, blockRegionSize
, copyPixelOperation
);
195 } else if (GDIPlus
.UseCocoaDrawable
) {
196 CopyFromScreenMac (sourceX
, sourceY
, destinationX
, destinationY
, blockRegionSize
, copyPixelOperation
);
198 CopyFromScreenWin32 (sourceX
, sourceY
, destinationX
, destinationY
, blockRegionSize
, copyPixelOperation
);
202 private void CopyFromScreenWin32 (int sourceX
, int sourceY
, int destinationX
, int destinationY
, Size blockRegionSize
, CopyPixelOperation copyPixelOperation
)
204 IntPtr window
= GDIPlus
.GetDesktopWindow ();
205 IntPtr srcDC
= GDIPlus
.GetDC (window
);
206 IntPtr dstDC
= GetHdc ();
207 GDIPlus
.BitBlt (dstDC
, destinationX
, destinationY
, blockRegionSize
.Width
,
208 blockRegionSize
.Height
, srcDC
, sourceX
, sourceY
, (int) copyPixelOperation
);
210 GDIPlus
.ReleaseDC (IntPtr
.Zero
, srcDC
);
214 private void CopyFromScreenMac (int sourceX
, int sourceY
, int destinationX
, int destinationY
, Size blockRegionSize
, CopyPixelOperation copyPixelOperation
)
216 throw new NotImplementedException ();
219 private void CopyFromScreenX11 (int sourceX
, int sourceY
, int destinationX
, int destinationY
, Size blockRegionSize
, CopyPixelOperation copyPixelOperation
)
221 IntPtr window
, image
, defvisual
, vPtr
;
222 int AllPlanes
= ~
0, nitems
= 0, pixel
;
224 if (copyPixelOperation
!= CopyPixelOperation
.SourceCopy
)
225 throw new NotImplementedException ("Operation not implemented under X11");
227 if (GDIPlus
.Display
== IntPtr
.Zero
) {
228 GDIPlus
.Display
= GDIPlus
.XOpenDisplay (IntPtr
.Zero
);
231 window
= GDIPlus
.XRootWindow (GDIPlus
.Display
, 0);
232 defvisual
= GDIPlus
.XDefaultVisual (GDIPlus
.Display
, 0);
233 XVisualInfo visual
= new XVisualInfo ();
235 /* Get XVisualInfo for this visual */
236 visual
.visualid
= GDIPlus
.XVisualIDFromVisual(defvisual
);
237 vPtr
= GDIPlus
.XGetVisualInfo (GDIPlus
.Display
, 0x1 /* VisualIDMask */, ref visual
, ref nitems
);
238 visual
= (XVisualInfo
) Marshal
.PtrToStructure(vPtr
, typeof (XVisualInfo
));
240 Console
.WriteLine ("visual\t{0}", visual
.visual
);
241 Console
.WriteLine ("visualid\t{0}", visual
.visualid
);
242 Console
.WriteLine ("screen\t{0}", visual
.screen
);
243 Console
.WriteLine ("depth\t{0}", visual
.depth
);
244 Console
.WriteLine ("klass\t{0}", visual
.klass
);
245 Console
.WriteLine ("red_mask\t{0:X}", visual
.red_mask
);
246 Console
.WriteLine ("green_mask\t{0:X}", visual
.green_mask
);
247 Console
.WriteLine ("blue_mask\t{0:X}", visual
.blue_mask
);
248 Console
.WriteLine ("colormap_size\t{0}", visual
.colormap_size
);
249 Console
.WriteLine ("bits_per_rgb\t{0}", visual
.bits_per_rgb
);
251 image
= GDIPlus
.XGetImage (GDIPlus
.Display
, window
, sourceX
, sourceY
, blockRegionSize
.Width
,
252 blockRegionSize
.Height
, AllPlanes
, 2 /* ZPixmap*/);
253 if (image
== IntPtr
.Zero
) {
254 string s
= String
.Format ("XGetImage returned NULL when asked to for a {0}x{1} region block",
255 blockRegionSize
.Width
, blockRegionSize
.Height
);
256 throw new InvalidOperationException (s
);
259 Bitmap bmp
= new Bitmap (blockRegionSize
.Width
, blockRegionSize
.Height
);
260 int red
, blue
, green
;
261 int red_mask
= (int) visual
.red_mask
;
262 int blue_mask
= (int) visual
.blue_mask
;
263 int green_mask
= (int) visual
.green_mask
;
264 for (int y
= 0; y
< blockRegionSize
.Height
; y
++) {
265 for (int x
= 0; x
< blockRegionSize
.Width
; x
++) {
266 pixel
= GDIPlus
.XGetPixel (image
, x
, y
);
268 switch (visual
.depth
) {
269 case 16: /* 16bbp pixel transformation */
270 red
= (int) ((pixel
& red_mask
) >> 8) & 0xff;
271 green
= (int) (((pixel
& green_mask
) >> 3 )) & 0xff;
272 blue
= (int) ((pixel
& blue_mask
) << 3 ) & 0xff;
276 red
= (int) ((pixel
& red_mask
) >> 16) & 0xff;
277 green
= (int) (((pixel
& green_mask
) >> 8 )) & 0xff;
278 blue
= (int) ((pixel
& blue_mask
)) & 0xff;
281 string text
= Locale
.GetText ("{0}bbp depth not supported.", visual
.depth
);
282 throw new NotImplementedException (text
);
285 bmp
.SetPixel (x
, y
, Color
.FromArgb (255, red
, green
, blue
));
289 DrawImage (bmp
, destinationX
, destinationY
);
291 GDIPlus
.XDestroyImage (image
);
292 GDIPlus
.XFree (vPtr
);
295 public void Dispose ()
299 if (deviceContextHdc
!= IntPtr
.Zero
)
302 if (GDIPlus
.UseCarbonDrawable
|| GDIPlus
.UseCocoaDrawable
) {
304 if (maccontext
!= null)
305 maccontext
.Release ();
308 status
= GDIPlus
.GdipDeleteGraphics (nativeObject
);
309 nativeObject
= IntPtr
.Zero
;
310 GDIPlus
.CheckStatus (status
);
312 if (_metafileHolder
!= null)
314 var mh
= _metafileHolder
;
315 _metafileHolder
= null;
316 mh
.GraphicsDisposed();
322 GC
.SuppressFinalize(this);
326 public void DrawArc (Pen pen
, Rectangle rect
, float startAngle
, float sweepAngle
)
328 DrawArc (pen
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, startAngle
, sweepAngle
);
332 public void DrawArc (Pen pen
, RectangleF rect
, float startAngle
, float sweepAngle
)
334 DrawArc (pen
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, startAngle
, sweepAngle
);
338 public void DrawArc (Pen pen
, float x
, float y
, float width
, float height
, float startAngle
, float sweepAngle
)
342 throw new ArgumentNullException ("pen");
344 status
= GDIPlus
.GdipDrawArc (nativeObject
, pen
.NativePen
,
345 x
, y
, width
, height
, startAngle
, sweepAngle
);
346 GDIPlus
.CheckStatus (status
);
349 // Microsoft documentation states that the signature for this member should be
350 // public void DrawArc( Pen pen, int x, int y, int width, int height, int startAngle,
351 // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
352 public void DrawArc (Pen pen
, int x
, int y
, int width
, int height
, int startAngle
, int sweepAngle
)
356 throw new ArgumentNullException ("pen");
357 status
= GDIPlus
.GdipDrawArcI (nativeObject
, pen
.NativePen
,
358 x
, y
, width
, height
, startAngle
, sweepAngle
);
359 GDIPlus
.CheckStatus (status
);
362 public void DrawBezier (Pen pen
, PointF pt1
, PointF pt2
, PointF pt3
, PointF pt4
)
366 throw new ArgumentNullException ("pen");
367 status
= GDIPlus
.GdipDrawBezier (nativeObject
, pen
.NativePen
,
368 pt1
.X
, pt1
.Y
, pt2
.X
, pt2
.Y
, pt3
.X
,
369 pt3
.Y
, pt4
.X
, pt4
.Y
);
370 GDIPlus
.CheckStatus (status
);
373 public void DrawBezier (Pen pen
, Point pt1
, Point pt2
, Point pt3
, Point pt4
)
377 throw new ArgumentNullException ("pen");
378 status
= GDIPlus
.GdipDrawBezierI (nativeObject
, pen
.NativePen
,
379 pt1
.X
, pt1
.Y
, pt2
.X
, pt2
.Y
, pt3
.X
,
380 pt3
.Y
, pt4
.X
, pt4
.Y
);
381 GDIPlus
.CheckStatus (status
);
384 public void DrawBezier (Pen pen
, float x1
, float y1
, float x2
, float y2
, float x3
, float y3
, float x4
, float y4
)
388 throw new ArgumentNullException ("pen");
389 status
= GDIPlus
.GdipDrawBezier (nativeObject
, pen
.NativePen
, x1
,
390 y1
, x2
, y2
, x3
, y3
, x4
, y4
);
391 GDIPlus
.CheckStatus (status
);
394 public void DrawBeziers (Pen pen
, Point
[] points
)
397 throw new ArgumentNullException ("pen");
399 throw new ArgumentNullException ("points");
401 int length
= points
.Length
;
407 for (int i
= 0; i
< length
- 1; i
+= 3) {
408 Point p1
= points
[i
];
409 Point p2
= points
[i
+ 1];
410 Point p3
= points
[i
+ 2];
411 Point p4
= points
[i
+ 3];
413 status
= GDIPlus
.GdipDrawBezier (nativeObject
,
415 p1
.X
, p1
.Y
, p2
.X
, p2
.Y
,
416 p3
.X
, p3
.Y
, p4
.X
, p4
.Y
);
417 GDIPlus
.CheckStatus (status
);
421 public void DrawBeziers (Pen pen
, PointF
[] points
)
424 throw new ArgumentNullException ("pen");
426 throw new ArgumentNullException ("points");
428 int length
= points
.Length
;
434 for (int i
= 0; i
< length
- 1; i
+= 3) {
435 PointF p1
= points
[i
];
436 PointF p2
= points
[i
+ 1];
437 PointF p3
= points
[i
+ 2];
438 PointF p4
= points
[i
+ 3];
440 status
= GDIPlus
.GdipDrawBezier (nativeObject
,
442 p1
.X
, p1
.Y
, p2
.X
, p2
.Y
,
443 p3
.X
, p3
.Y
, p4
.X
, p4
.Y
);
444 GDIPlus
.CheckStatus (status
);
449 public void DrawClosedCurve (Pen pen
, PointF
[] points
)
452 throw new ArgumentNullException ("pen");
454 throw new ArgumentNullException ("points");
457 status
= GDIPlus
.GdipDrawClosedCurve (nativeObject
, pen
.NativePen
, points
, points
.Length
);
458 GDIPlus
.CheckStatus (status
);
461 public void DrawClosedCurve (Pen pen
, Point
[] points
)
464 throw new ArgumentNullException ("pen");
466 throw new ArgumentNullException ("points");
469 status
= GDIPlus
.GdipDrawClosedCurveI (nativeObject
, pen
.NativePen
, points
, points
.Length
);
470 GDIPlus
.CheckStatus (status
);
473 // according to MSDN fillmode "is required but ignored" which makes _some_ sense since the unmanaged
474 // GDI+ call doesn't support it (issue spotted using Gendarme's AvoidUnusedParametersRule)
475 public void DrawClosedCurve (Pen pen
, Point
[] points
, float tension
, FillMode fillmode
)
478 throw new ArgumentNullException ("pen");
480 throw new ArgumentNullException ("points");
483 status
= GDIPlus
.GdipDrawClosedCurve2I (nativeObject
, pen
.NativePen
, points
, points
.Length
, tension
);
484 GDIPlus
.CheckStatus (status
);
487 // according to MSDN fillmode "is required but ignored" which makes _some_ sense since the unmanaged
488 // GDI+ call doesn't support it (issue spotted using Gendarme's AvoidUnusedParametersRule)
489 public void DrawClosedCurve (Pen pen
, PointF
[] points
, float tension
, FillMode fillmode
)
492 throw new ArgumentNullException ("pen");
494 throw new ArgumentNullException ("points");
497 status
= GDIPlus
.GdipDrawClosedCurve2 (nativeObject
, pen
.NativePen
, points
, points
.Length
, tension
);
498 GDIPlus
.CheckStatus (status
);
501 public void DrawCurve (Pen pen
, Point
[] points
)
504 throw new ArgumentNullException ("pen");
506 throw new ArgumentNullException ("points");
509 status
= GDIPlus
.GdipDrawCurveI (nativeObject
, pen
.NativePen
, points
, points
.Length
);
510 GDIPlus
.CheckStatus (status
);
513 public void DrawCurve (Pen pen
, PointF
[] points
)
516 throw new ArgumentNullException ("pen");
518 throw new ArgumentNullException ("points");
521 status
= GDIPlus
.GdipDrawCurve (nativeObject
, pen
.NativePen
, points
, points
.Length
);
522 GDIPlus
.CheckStatus (status
);
525 public void DrawCurve (Pen pen
, PointF
[] points
, float tension
)
528 throw new ArgumentNullException ("pen");
530 throw new ArgumentNullException ("points");
533 status
= GDIPlus
.GdipDrawCurve2 (nativeObject
, pen
.NativePen
, points
, points
.Length
, tension
);
534 GDIPlus
.CheckStatus (status
);
537 public void DrawCurve (Pen pen
, Point
[] points
, float tension
)
540 throw new ArgumentNullException ("pen");
542 throw new ArgumentNullException ("points");
545 status
= GDIPlus
.GdipDrawCurve2I (nativeObject
, pen
.NativePen
, points
, points
.Length
, tension
);
546 GDIPlus
.CheckStatus (status
);
549 public void DrawCurve (Pen pen
, PointF
[] points
, int offset
, int numberOfSegments
)
552 throw new ArgumentNullException ("pen");
554 throw new ArgumentNullException ("points");
557 status
= GDIPlus
.GdipDrawCurve3 (nativeObject
, pen
.NativePen
,
558 points
, points
.Length
, offset
,
559 numberOfSegments
, 0.5f
);
560 GDIPlus
.CheckStatus (status
);
563 public void DrawCurve (Pen pen
, Point
[] points
, int offset
, int numberOfSegments
, float tension
)
566 throw new ArgumentNullException ("pen");
568 throw new ArgumentNullException ("points");
571 status
= GDIPlus
.GdipDrawCurve3I (nativeObject
, pen
.NativePen
,
572 points
, points
.Length
, offset
,
573 numberOfSegments
, tension
);
574 GDIPlus
.CheckStatus (status
);
577 public void DrawCurve (Pen pen
, PointF
[] points
, int offset
, int numberOfSegments
, float tension
)
580 throw new ArgumentNullException ("pen");
582 throw new ArgumentNullException ("points");
585 status
= GDIPlus
.GdipDrawCurve3 (nativeObject
, pen
.NativePen
,
586 points
, points
.Length
, offset
,
587 numberOfSegments
, tension
);
588 GDIPlus
.CheckStatus (status
);
591 public void DrawEllipse (Pen pen
, Rectangle rect
)
594 throw new ArgumentNullException ("pen");
596 DrawEllipse (pen
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
599 public void DrawEllipse (Pen pen
, RectangleF rect
)
602 throw new ArgumentNullException ("pen");
603 DrawEllipse (pen
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
606 public void DrawEllipse (Pen pen
, int x
, int y
, int width
, int height
)
609 throw new ArgumentNullException ("pen");
611 status
= GDIPlus
.GdipDrawEllipseI (nativeObject
, pen
.NativePen
, x
, y
, width
, height
);
612 GDIPlus
.CheckStatus (status
);
615 public void DrawEllipse (Pen pen
, float x
, float y
, float width
, float height
)
618 throw new ArgumentNullException ("pen");
619 Status status
= GDIPlus
.GdipDrawEllipse (nativeObject
, pen
.NativePen
, x
, y
, width
, height
);
620 GDIPlus
.CheckStatus (status
);
623 public void DrawIcon (Icon icon
, Rectangle targetRect
)
626 throw new ArgumentNullException ("icon");
628 DrawImage (icon
.GetInternalBitmap (), targetRect
);
631 public void DrawIcon (Icon icon
, int x
, int y
)
634 throw new ArgumentNullException ("icon");
636 DrawImage (icon
.GetInternalBitmap (), x
, y
);
639 public void DrawIconUnstretched (Icon icon
, Rectangle targetRect
)
642 throw new ArgumentNullException ("icon");
644 DrawImageUnscaled (icon
.GetInternalBitmap (), targetRect
);
647 public void DrawImage (Image image
, RectangleF rect
)
650 throw new ArgumentNullException ("image");
652 Status status
= GDIPlus
.GdipDrawImageRect(nativeObject
, image
.NativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
653 GDIPlus
.CheckStatus (status
);
656 public void DrawImage (Image image
, PointF point
)
659 throw new ArgumentNullException ("image");
661 Status status
= GDIPlus
.GdipDrawImage (nativeObject
, image
.NativeObject
, point
.X
, point
.Y
);
662 GDIPlus
.CheckStatus (status
);
665 public void DrawImage (Image image
, Point
[] destPoints
)
668 throw new ArgumentNullException ("image");
669 if (destPoints
== null)
670 throw new ArgumentNullException ("destPoints");
672 Status status
= GDIPlus
.GdipDrawImagePointsI (nativeObject
, image
.NativeObject
, destPoints
, destPoints
.Length
);
673 GDIPlus
.CheckStatus (status
);
676 public void DrawImage (Image image
, Point point
)
679 throw new ArgumentNullException ("image");
680 DrawImage (image
, point
.X
, point
.Y
);
683 public void DrawImage (Image image
, Rectangle rect
)
686 throw new ArgumentNullException ("image");
687 DrawImage (image
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
690 public void DrawImage (Image image
, PointF
[] destPoints
)
693 throw new ArgumentNullException ("image");
694 if (destPoints
== null)
695 throw new ArgumentNullException ("destPoints");
696 Status status
= GDIPlus
.GdipDrawImagePoints (nativeObject
, image
.NativeObject
, destPoints
, destPoints
.Length
);
697 GDIPlus
.CheckStatus (status
);
700 public void DrawImage (Image image
, int x
, int y
)
703 throw new ArgumentNullException ("image");
704 Status status
= GDIPlus
.GdipDrawImageI (nativeObject
, image
.NativeObject
, x
, y
);
705 GDIPlus
.CheckStatus (status
);
708 public void DrawImage (Image image
, float x
, float y
)
711 throw new ArgumentNullException ("image");
712 Status status
= GDIPlus
.GdipDrawImage (nativeObject
, image
.NativeObject
, x
, y
);
713 GDIPlus
.CheckStatus (status
);
716 public void DrawImage (Image image
, Rectangle destRect
, Rectangle srcRect
, GraphicsUnit srcUnit
)
719 throw new ArgumentNullException ("image");
720 Status status
= GDIPlus
.GdipDrawImageRectRectI (nativeObject
, image
.NativeObject
,
721 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
722 srcRect
.X
, srcRect
.Y
, srcRect
.Width
, srcRect
.Height
,
723 srcUnit
, IntPtr
.Zero
, null, IntPtr
.Zero
);
724 GDIPlus
.CheckStatus (status
);
727 public void DrawImage (Image image
, RectangleF destRect
, RectangleF srcRect
, GraphicsUnit srcUnit
)
730 throw new ArgumentNullException ("image");
731 Status status
= GDIPlus
.GdipDrawImageRectRect (nativeObject
, image
.NativeObject
,
732 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
733 srcRect
.X
, srcRect
.Y
, srcRect
.Width
, srcRect
.Height
,
734 srcUnit
, IntPtr
.Zero
, null, IntPtr
.Zero
);
735 GDIPlus
.CheckStatus (status
);
738 public void DrawImage (Image image
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit srcUnit
)
741 throw new ArgumentNullException ("image");
742 if (destPoints
== null)
743 throw new ArgumentNullException ("destPoints");
745 Status status
= GDIPlus
.GdipDrawImagePointsRectI (nativeObject
, image
.NativeObject
,
746 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
747 srcRect
.Width
, srcRect
.Height
, srcUnit
, IntPtr
.Zero
,
749 GDIPlus
.CheckStatus (status
);
752 public void DrawImage (Image image
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit srcUnit
)
755 throw new ArgumentNullException ("image");
756 if (destPoints
== null)
757 throw new ArgumentNullException ("destPoints");
759 Status status
= GDIPlus
.GdipDrawImagePointsRect (nativeObject
, image
.NativeObject
,
760 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
761 srcRect
.Width
, srcRect
.Height
, srcUnit
, IntPtr
.Zero
,
763 GDIPlus
.CheckStatus (status
);
766 public void DrawImage (Image image
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit srcUnit
,
767 ImageAttributes imageAttr
)
770 throw new ArgumentNullException ("image");
771 if (destPoints
== null)
772 throw new ArgumentNullException ("destPoints");
773 Status status
= GDIPlus
.GdipDrawImagePointsRectI (nativeObject
, image
.NativeObject
,
774 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
775 srcRect
.Width
, srcRect
.Height
, srcUnit
,
776 imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, null, IntPtr
.Zero
);
777 GDIPlus
.CheckStatus (status
);
780 public void DrawImage (Image image
, float x
, float y
, float width
, float height
)
783 throw new ArgumentNullException ("image");
784 Status status
= GDIPlus
.GdipDrawImageRect(nativeObject
, image
.NativeObject
, x
, y
,
786 GDIPlus
.CheckStatus (status
);
789 public void DrawImage (Image image
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit srcUnit
,
790 ImageAttributes imageAttr
)
793 throw new ArgumentNullException ("image");
794 if (destPoints
== null)
795 throw new ArgumentNullException ("destPoints");
796 Status status
= GDIPlus
.GdipDrawImagePointsRect (nativeObject
, image
.NativeObject
,
797 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
798 srcRect
.Width
, srcRect
.Height
, srcUnit
,
799 imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, null, IntPtr
.Zero
);
800 GDIPlus
.CheckStatus (status
);
803 public void DrawImage (Image image
, int x
, int y
, Rectangle srcRect
, GraphicsUnit srcUnit
)
806 throw new ArgumentNullException ("image");
807 Status status
= GDIPlus
.GdipDrawImagePointRectI(nativeObject
, image
.NativeObject
, x
, y
, srcRect
.X
, srcRect
.Y
, srcRect
.Width
, srcRect
.Height
, srcUnit
);
808 GDIPlus
.CheckStatus (status
);
811 public void DrawImage (Image image
, int x
, int y
, int width
, int height
)
814 throw new ArgumentNullException ("image");
815 Status status
= GDIPlus
.GdipDrawImageRectI (nativeObject
, image
.nativeObject
, x
, y
, width
, height
);
816 GDIPlus
.CheckStatus (status
);
819 public void DrawImage (Image image
, float x
, float y
, RectangleF srcRect
, GraphicsUnit srcUnit
)
822 throw new ArgumentNullException ("image");
823 Status status
= GDIPlus
.GdipDrawImagePointRect (nativeObject
, image
.nativeObject
, x
, y
, srcRect
.X
, srcRect
.Y
, srcRect
.Width
, srcRect
.Height
, srcUnit
);
824 GDIPlus
.CheckStatus (status
);
827 public void DrawImage (Image image
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit srcUnit
, ImageAttributes imageAttr
, DrawImageAbort callback
)
830 throw new ArgumentNullException ("image");
831 if (destPoints
== null)
832 throw new ArgumentNullException ("destPoints");
833 Status status
= GDIPlus
.GdipDrawImagePointsRect (nativeObject
, image
.NativeObject
,
834 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
835 srcRect
.Width
, srcRect
.Height
, srcUnit
,
836 imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, callback
, IntPtr
.Zero
);
837 GDIPlus
.CheckStatus (status
);
840 public void DrawImage (Image image
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit srcUnit
, ImageAttributes imageAttr
, DrawImageAbort callback
)
843 throw new ArgumentNullException ("image");
844 if (destPoints
== null)
845 throw new ArgumentNullException ("destPoints");
847 Status status
= GDIPlus
.GdipDrawImagePointsRectI (nativeObject
, image
.NativeObject
,
848 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
849 srcRect
.Width
, srcRect
.Height
, srcUnit
,
850 imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, callback
, IntPtr
.Zero
);
851 GDIPlus
.CheckStatus (status
);
854 public void DrawImage (Image image
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit srcUnit
, ImageAttributes imageAttr
, DrawImageAbort callback
, int callbackData
)
857 throw new ArgumentNullException ("image");
858 if (destPoints
== null)
859 throw new ArgumentNullException ("destPoints");
861 Status status
= GDIPlus
.GdipDrawImagePointsRectI (nativeObject
, image
.NativeObject
,
862 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
863 srcRect
.Width
, srcRect
.Height
, srcUnit
,
864 imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, callback
, (IntPtr
) callbackData
);
865 GDIPlus
.CheckStatus (status
);
868 public void DrawImage (Image image
, Rectangle destRect
, float srcX
, float srcY
, float srcWidth
, float srcHeight
, GraphicsUnit srcUnit
)
871 throw new ArgumentNullException ("image");
872 Status status
= GDIPlus
.GdipDrawImageRectRect (nativeObject
, image
.NativeObject
,
873 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
874 srcX
, srcY
, srcWidth
, srcHeight
, srcUnit
, IntPtr
.Zero
,
876 GDIPlus
.CheckStatus (status
);
879 public void DrawImage (Image image
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit srcUnit
, ImageAttributes imageAttr
, DrawImageAbort callback
, int callbackData
)
881 Status status
= GDIPlus
.GdipDrawImagePointsRect (nativeObject
, image
.NativeObject
,
882 destPoints
, destPoints
.Length
, srcRect
.X
, srcRect
.Y
,
883 srcRect
.Width
, srcRect
.Height
, srcUnit
,
884 imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, callback
, (IntPtr
) callbackData
);
885 GDIPlus
.CheckStatus (status
);
888 public void DrawImage (Image image
, Rectangle destRect
, int srcX
, int srcY
, int srcWidth
, int srcHeight
, GraphicsUnit srcUnit
)
891 throw new ArgumentNullException ("image");
892 Status status
= GDIPlus
.GdipDrawImageRectRectI (nativeObject
, image
.NativeObject
,
893 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
894 srcX
, srcY
, srcWidth
, srcHeight
, srcUnit
, IntPtr
.Zero
,
896 GDIPlus
.CheckStatus (status
);
899 public void DrawImage (Image image
, Rectangle destRect
, float srcX
, float srcY
, float srcWidth
, float srcHeight
, GraphicsUnit srcUnit
, ImageAttributes imageAttrs
)
902 throw new ArgumentNullException ("image");
903 Status status
= GDIPlus
.GdipDrawImageRectRect (nativeObject
, image
.NativeObject
,
904 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
905 srcX
, srcY
, srcWidth
, srcHeight
, srcUnit
,
906 imageAttrs
!= null ? imageAttrs
.nativeImageAttributes
: IntPtr
.Zero
, null, IntPtr
.Zero
);
907 GDIPlus
.CheckStatus (status
);
910 public void DrawImage (Image image
, Rectangle destRect
, int srcX
, int srcY
, int srcWidth
, int srcHeight
, GraphicsUnit srcUnit
, ImageAttributes imageAttr
)
913 throw new ArgumentNullException ("image");
914 Status status
= GDIPlus
.GdipDrawImageRectRectI (nativeObject
, image
.NativeObject
,
915 destRect
.X
, destRect
.Y
, destRect
.Width
,
916 destRect
.Height
, srcX
, srcY
, srcWidth
, srcHeight
,
917 srcUnit
, imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, null, IntPtr
.Zero
);
918 GDIPlus
.CheckStatus (status
);
921 public void DrawImage (Image image
, Rectangle destRect
, int srcX
, int srcY
, int srcWidth
, int srcHeight
, GraphicsUnit srcUnit
, ImageAttributes imageAttr
, DrawImageAbort callback
)
924 throw new ArgumentNullException ("image");
925 Status status
= GDIPlus
.GdipDrawImageRectRectI (nativeObject
, image
.NativeObject
,
926 destRect
.X
, destRect
.Y
, destRect
.Width
,
927 destRect
.Height
, srcX
, srcY
, srcWidth
, srcHeight
,
928 srcUnit
, imageAttr
!= null ? imageAttr
.nativeImageAttributes
: IntPtr
.Zero
, callback
,
930 GDIPlus
.CheckStatus (status
);
933 public void DrawImage (Image image
, Rectangle destRect
, float srcX
, float srcY
, float srcWidth
, float srcHeight
, GraphicsUnit srcUnit
, ImageAttributes imageAttrs
, DrawImageAbort callback
)
936 throw new ArgumentNullException ("image");
937 Status status
= GDIPlus
.GdipDrawImageRectRect (nativeObject
, image
.NativeObject
,
938 destRect
.X
, destRect
.Y
, destRect
.Width
,
939 destRect
.Height
, srcX
, srcY
, srcWidth
, srcHeight
,
940 srcUnit
, imageAttrs
!= null ? imageAttrs
.nativeImageAttributes
: IntPtr
.Zero
,
941 callback
, IntPtr
.Zero
);
942 GDIPlus
.CheckStatus (status
);
945 public void DrawImage (Image image
, Rectangle destRect
, float srcX
, float srcY
, float srcWidth
, float srcHeight
, GraphicsUnit srcUnit
, ImageAttributes imageAttrs
, DrawImageAbort callback
, IntPtr callbackData
)
948 throw new ArgumentNullException ("image");
949 Status status
= GDIPlus
.GdipDrawImageRectRect (nativeObject
, image
.NativeObject
,
950 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
951 srcX
, srcY
, srcWidth
, srcHeight
, srcUnit
,
952 imageAttrs
!= null ? imageAttrs
.nativeImageAttributes
: IntPtr
.Zero
, callback
, callbackData
);
953 GDIPlus
.CheckStatus (status
);
956 public void DrawImage (Image image
, Rectangle destRect
, int srcX
, int srcY
, int srcWidth
, int srcHeight
, GraphicsUnit srcUnit
, ImageAttributes imageAttrs
, DrawImageAbort callback
, IntPtr callbackData
)
959 throw new ArgumentNullException ("image");
960 Status status
= GDIPlus
.GdipDrawImageRectRect (nativeObject
, image
.NativeObject
,
961 destRect
.X
, destRect
.Y
, destRect
.Width
, destRect
.Height
,
962 srcX
, srcY
, srcWidth
, srcHeight
, srcUnit
,
963 imageAttrs
!= null ? imageAttrs
.nativeImageAttributes
: IntPtr
.Zero
, callback
, callbackData
);
964 GDIPlus
.CheckStatus (status
);
967 public void DrawImageUnscaled (Image image
, Point point
)
969 DrawImageUnscaled (image
, point
.X
, point
.Y
);
972 public void DrawImageUnscaled (Image image
, Rectangle rect
)
974 DrawImageUnscaled (image
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
977 public void DrawImageUnscaled (Image image
, int x
, int y
)
980 throw new ArgumentNullException ("image");
981 DrawImage (image
, x
, y
, image
.Width
, image
.Height
);
984 public void DrawImageUnscaled (Image image
, int x
, int y
, int width
, int height
)
987 throw new ArgumentNullException ("image");
989 // avoid creating an empty, or negative w/h, bitmap...
990 if ((width
<= 0) || (height
<= 0))
993 using (Image tmpImg
= new Bitmap (width
, height
)) {
994 using (Graphics g
= FromImage (tmpImg
)) {
995 g
.DrawImage (image
, 0, 0, image
.Width
, image
.Height
);
996 DrawImage (tmpImg
, x
, y
, width
, height
);
1001 public void DrawImageUnscaledAndClipped (Image image
, Rectangle rect
)
1004 throw new ArgumentNullException ("image");
1006 int width
= (image
.Width
> rect
.Width
) ? rect
.Width
: image
.Width
;
1007 int height
= (image
.Height
> rect
.Height
) ? rect
.Height
: image
.Height
;
1009 DrawImageUnscaled (image
, rect
.X
, rect
.Y
, width
, height
);
1012 public void DrawLine (Pen pen
, PointF pt1
, PointF pt2
)
1015 throw new ArgumentNullException ("pen");
1016 Status status
= GDIPlus
.GdipDrawLine (nativeObject
, pen
.NativePen
,
1017 pt1
.X
, pt1
.Y
, pt2
.X
, pt2
.Y
);
1018 GDIPlus
.CheckStatus (status
);
1021 public void DrawLine (Pen pen
, Point pt1
, Point pt2
)
1024 throw new ArgumentNullException ("pen");
1025 Status status
= GDIPlus
.GdipDrawLineI (nativeObject
, pen
.NativePen
,
1026 pt1
.X
, pt1
.Y
, pt2
.X
, pt2
.Y
);
1027 GDIPlus
.CheckStatus (status
);
1030 public void DrawLine (Pen pen
, int x1
, int y1
, int x2
, int y2
)
1033 throw new ArgumentNullException ("pen");
1034 Status status
= GDIPlus
.GdipDrawLineI (nativeObject
, pen
.NativePen
, x1
, y1
, x2
, y2
);
1035 GDIPlus
.CheckStatus (status
);
1038 public void DrawLine (Pen pen
, float x1
, float y1
, float x2
, float y2
)
1041 throw new ArgumentNullException ("pen");
1042 if (!float.IsNaN(x1
) && !float.IsNaN(y1
) &&
1043 !float.IsNaN(x2
) && !float.IsNaN(y2
)) {
1044 Status status
= GDIPlus
.GdipDrawLine (nativeObject
, pen
.NativePen
, x1
, y1
, x2
, y2
);
1045 GDIPlus
.CheckStatus (status
);
1049 public void DrawLines (Pen pen
, PointF
[] points
)
1052 throw new ArgumentNullException ("pen");
1054 throw new ArgumentNullException ("points");
1055 Status status
= GDIPlus
.GdipDrawLines (nativeObject
, pen
.NativePen
, points
, points
.Length
);
1056 GDIPlus
.CheckStatus (status
);
1059 public void DrawLines (Pen pen
, Point
[] points
)
1062 throw new ArgumentNullException ("pen");
1064 throw new ArgumentNullException ("points");
1065 Status status
= GDIPlus
.GdipDrawLinesI (nativeObject
, pen
.NativePen
, points
, points
.Length
);
1066 GDIPlus
.CheckStatus (status
);
1069 public void DrawPath (Pen pen
, GraphicsPath path
)
1072 throw new ArgumentNullException ("pen");
1074 throw new ArgumentNullException ("path");
1075 Status status
= GDIPlus
.GdipDrawPath (nativeObject
, pen
.NativePen
, path
.nativePath
);
1076 GDIPlus
.CheckStatus (status
);
1079 public void DrawPie (Pen pen
, Rectangle rect
, float startAngle
, float sweepAngle
)
1082 throw new ArgumentNullException ("pen");
1083 DrawPie (pen
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, startAngle
, sweepAngle
);
1086 public void DrawPie (Pen pen
, RectangleF rect
, float startAngle
, float sweepAngle
)
1089 throw new ArgumentNullException ("pen");
1090 DrawPie (pen
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, startAngle
, sweepAngle
);
1093 public void DrawPie (Pen pen
, float x
, float y
, float width
, float height
, float startAngle
, float sweepAngle
)
1096 throw new ArgumentNullException ("pen");
1097 Status status
= GDIPlus
.GdipDrawPie (nativeObject
, pen
.NativePen
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1098 GDIPlus
.CheckStatus (status
);
1101 // Microsoft documentation states that the signature for this member should be
1102 // public void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle
1103 // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
1104 public void DrawPie (Pen pen
, int x
, int y
, int width
, int height
, int startAngle
, int sweepAngle
)
1107 throw new ArgumentNullException ("pen");
1108 Status status
= GDIPlus
.GdipDrawPieI (nativeObject
, pen
.NativePen
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1109 GDIPlus
.CheckStatus (status
);
1112 public void DrawPolygon (Pen pen
, Point
[] points
)
1115 throw new ArgumentNullException ("pen");
1117 throw new ArgumentNullException ("points");
1118 Status status
= GDIPlus
.GdipDrawPolygonI (nativeObject
, pen
.NativePen
, points
, points
.Length
);
1119 GDIPlus
.CheckStatus (status
);
1122 public void DrawPolygon (Pen pen
, PointF
[] points
)
1125 throw new ArgumentNullException ("pen");
1127 throw new ArgumentNullException ("points");
1128 Status status
= GDIPlus
.GdipDrawPolygon (nativeObject
, pen
.NativePen
, points
, points
.Length
);
1129 GDIPlus
.CheckStatus (status
);
1132 public void DrawRectangle (Pen pen
, Rectangle rect
)
1135 throw new ArgumentNullException ("pen");
1136 DrawRectangle (pen
, rect
.Left
, rect
.Top
, rect
.Width
, rect
.Height
);
1139 public void DrawRectangle (Pen pen
, float x
, float y
, float width
, float height
)
1142 throw new ArgumentNullException ("pen");
1143 Status status
= GDIPlus
.GdipDrawRectangle (nativeObject
, pen
.NativePen
, x
, y
, width
, height
);
1144 GDIPlus
.CheckStatus (status
);
1147 public void DrawRectangle (Pen pen
, int x
, int y
, int width
, int height
)
1150 throw new ArgumentNullException ("pen");
1151 Status status
= GDIPlus
.GdipDrawRectangleI (nativeObject
, pen
.NativePen
, x
, y
, width
, height
);
1152 GDIPlus
.CheckStatus (status
);
1155 public void DrawRectangles (Pen pen
, RectangleF
[] rects
)
1158 throw new ArgumentNullException ("image");
1160 throw new ArgumentNullException ("rects");
1161 Status status
= GDIPlus
.GdipDrawRectangles (nativeObject
, pen
.NativePen
, rects
, rects
.Length
);
1162 GDIPlus
.CheckStatus (status
);
1165 public void DrawRectangles (Pen pen
, Rectangle
[] rects
)
1168 throw new ArgumentNullException ("image");
1170 throw new ArgumentNullException ("rects");
1171 Status status
= GDIPlus
.GdipDrawRectanglesI (nativeObject
, pen
.NativePen
, rects
, rects
.Length
);
1172 GDIPlus
.CheckStatus (status
);
1175 public void DrawString (string s
, Font font
, Brush brush
, RectangleF layoutRectangle
)
1177 DrawString (s
, font
, brush
, layoutRectangle
, null);
1180 public void DrawString (string s
, Font font
, Brush brush
, PointF point
)
1182 DrawString (s
, font
, brush
, new RectangleF (point
.X
, point
.Y
, 0, 0), null);
1185 public void DrawString (string s
, Font font
, Brush brush
, PointF point
, StringFormat format
)
1187 DrawString(s
, font
, brush
, new RectangleF(point
.X
, point
.Y
, 0, 0), format
);
1190 public void DrawString (string s
, Font font
, Brush brush
, float x
, float y
)
1192 DrawString (s
, font
, brush
, new RectangleF (x
, y
, 0, 0), null);
1195 public void DrawString (string s
, Font font
, Brush brush
, float x
, float y
, StringFormat format
)
1197 DrawString (s
, font
, brush
, new RectangleF(x
, y
, 0, 0), format
);
1200 public void DrawString (string s
, Font font
, Brush brush
, RectangleF layoutRectangle
, StringFormat format
)
1203 throw new ArgumentNullException ("font");
1205 throw new ArgumentNullException ("brush");
1206 if (s
== null || s
.Length
== 0)
1209 Status status
= GDIPlus
.GdipDrawString (nativeObject
, s
, s
.Length
, font
.NativeObject
, ref layoutRectangle
, format
!= null ? format
.NativeObject
: IntPtr
.Zero
, brush
.NativeBrush
);
1210 GDIPlus
.CheckStatus (status
);
1213 public void EndContainer (GraphicsContainer container
)
1215 if (container
== null)
1216 throw new ArgumentNullException ("container");
1217 Status status
= GDIPlus
.GdipEndContainer(nativeObject
, container
.NativeObject
);
1218 GDIPlus
.CheckStatus (status
);
1221 private const string MetafileEnumeration
= "Metafiles enumeration, for both WMF and EMF formats, isn't supported.";
1223 [MonoTODO (MetafileEnumeration
)]
1224 public void EnumerateMetafile (Metafile metafile
, Point
[] destPoints
, EnumerateMetafileProc callback
)
1226 throw new NotImplementedException ();
1229 [MonoTODO (MetafileEnumeration
)]
1230 public void EnumerateMetafile (Metafile metafile
, RectangleF destRect
, EnumerateMetafileProc callback
)
1232 throw new NotImplementedException ();
1235 [MonoTODO (MetafileEnumeration
)]
1236 public void EnumerateMetafile (Metafile metafile
, PointF
[] destPoints
, EnumerateMetafileProc callback
)
1238 throw new NotImplementedException ();
1241 [MonoTODO (MetafileEnumeration
)]
1242 public void EnumerateMetafile (Metafile metafile
, Rectangle destRect
, EnumerateMetafileProc callback
)
1244 throw new NotImplementedException ();
1247 [MonoTODO (MetafileEnumeration
)]
1248 public void EnumerateMetafile (Metafile metafile
, Point destPoint
, EnumerateMetafileProc callback
)
1250 throw new NotImplementedException ();
1253 [MonoTODO (MetafileEnumeration
)]
1254 public void EnumerateMetafile (Metafile metafile
, PointF destPoint
, EnumerateMetafileProc callback
)
1256 throw new NotImplementedException ();
1259 [MonoTODO (MetafileEnumeration
)]
1260 public void EnumerateMetafile (Metafile metafile
, PointF destPoint
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1262 throw new NotImplementedException ();
1265 [MonoTODO (MetafileEnumeration
)]
1266 public void EnumerateMetafile (Metafile metafile
, Rectangle destRect
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1268 throw new NotImplementedException ();
1271 [MonoTODO (MetafileEnumeration
)]
1272 public void EnumerateMetafile (Metafile metafile
, PointF
[] destPoints
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1274 throw new NotImplementedException ();
1277 [MonoTODO (MetafileEnumeration
)]
1278 public void EnumerateMetafile (Metafile metafile
, Point destPoint
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1280 throw new NotImplementedException ();
1283 [MonoTODO (MetafileEnumeration
)]
1284 public void EnumerateMetafile (Metafile metafile
, Point
[] destPoints
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1286 throw new NotImplementedException ();
1289 [MonoTODO (MetafileEnumeration
)]
1290 public void EnumerateMetafile (Metafile metafile
, RectangleF destRect
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1292 throw new NotImplementedException ();
1295 [MonoTODO (MetafileEnumeration
)]
1296 public void EnumerateMetafile (Metafile metafile
, PointF destPoint
, RectangleF srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
)
1298 throw new NotImplementedException ();
1301 [MonoTODO (MetafileEnumeration
)]
1302 public void EnumerateMetafile (Metafile metafile
, Point destPoint
, Rectangle srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
)
1304 throw new NotImplementedException ();
1307 [MonoTODO (MetafileEnumeration
)]
1308 public void EnumerateMetafile (Metafile metafile
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
)
1310 throw new NotImplementedException ();
1313 [MonoTODO (MetafileEnumeration
)]
1314 public void EnumerateMetafile (Metafile metafile
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
)
1316 throw new NotImplementedException ();
1319 [MonoTODO (MetafileEnumeration
)]
1320 public void EnumerateMetafile (Metafile metafile
, RectangleF destRect
, RectangleF srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
)
1322 throw new NotImplementedException ();
1325 [MonoTODO (MetafileEnumeration
)]
1326 public void EnumerateMetafile (Metafile metafile
, Rectangle destRect
, Rectangle srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
)
1328 throw new NotImplementedException ();
1331 [MonoTODO (MetafileEnumeration
)]
1332 public void EnumerateMetafile (Metafile metafile
, RectangleF destRect
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1334 throw new NotImplementedException ();
1337 [MonoTODO (MetafileEnumeration
)]
1338 public void EnumerateMetafile (Metafile metafile
, Point destPoint
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1340 throw new NotImplementedException ();
1343 [MonoTODO (MetafileEnumeration
)]
1344 public void EnumerateMetafile (Metafile metafile
, PointF destPoint
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1346 throw new NotImplementedException ();
1349 [MonoTODO (MetafileEnumeration
)]
1350 public void EnumerateMetafile (Metafile metafile
, Point
[] destPoints
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1352 throw new NotImplementedException ();
1355 [MonoTODO (MetafileEnumeration
)]
1356 public void EnumerateMetafile (Metafile metafile
, PointF
[] destPoints
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1358 throw new NotImplementedException ();
1361 [MonoTODO (MetafileEnumeration
)]
1362 public void EnumerateMetafile (Metafile metafile
, Rectangle destRect
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1364 throw new NotImplementedException ();
1367 [MonoTODO (MetafileEnumeration
)]
1368 public void EnumerateMetafile (Metafile metafile
, Rectangle destRect
, Rectangle srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1370 throw new NotImplementedException ();
1373 [MonoTODO (MetafileEnumeration
)]
1374 public void EnumerateMetafile (Metafile metafile
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1376 throw new NotImplementedException ();
1379 [MonoTODO (MetafileEnumeration
)]
1380 public void EnumerateMetafile (Metafile metafile
, RectangleF destRect
, RectangleF srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1382 throw new NotImplementedException ();
1385 [MonoTODO (MetafileEnumeration
)]
1386 public void EnumerateMetafile (Metafile metafile
, PointF destPoint
, RectangleF srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1388 throw new NotImplementedException ();
1391 [MonoTODO (MetafileEnumeration
)]
1392 public void EnumerateMetafile (Metafile metafile
, Point destPoint
, Rectangle srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1394 throw new NotImplementedException ();
1397 [MonoTODO (MetafileEnumeration
)]
1398 public void EnumerateMetafile (Metafile metafile
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit srcUnit
, EnumerateMetafileProc callback
, IntPtr callbackData
)
1400 throw new NotImplementedException ();
1403 [MonoTODO (MetafileEnumeration
)]
1404 public void EnumerateMetafile (Metafile metafile
, Point
[] destPoints
, Rectangle srcRect
, GraphicsUnit unit
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1406 throw new NotImplementedException ();
1409 [MonoTODO (MetafileEnumeration
)]
1410 public void EnumerateMetafile (Metafile metafile
, Rectangle destRect
, Rectangle srcRect
, GraphicsUnit unit
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1412 throw new NotImplementedException ();
1415 [MonoTODO (MetafileEnumeration
)]
1416 public void EnumerateMetafile (Metafile metafile
, Point destPoint
, Rectangle srcRect
, GraphicsUnit unit
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1418 throw new NotImplementedException ();
1421 [MonoTODO (MetafileEnumeration
)]
1422 public void EnumerateMetafile (Metafile metafile
, RectangleF destRect
, RectangleF srcRect
, GraphicsUnit unit
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1424 throw new NotImplementedException ();
1427 [MonoTODO (MetafileEnumeration
)]
1428 public void EnumerateMetafile (Metafile metafile
, PointF
[] destPoints
, RectangleF srcRect
, GraphicsUnit unit
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1430 throw new NotImplementedException ();
1433 [MonoTODO (MetafileEnumeration
)]
1434 public void EnumerateMetafile (Metafile metafile
, PointF destPoint
, RectangleF srcRect
, GraphicsUnit unit
, EnumerateMetafileProc callback
, IntPtr callbackData
, ImageAttributes imageAttr
)
1436 throw new NotImplementedException ();
1439 public void ExcludeClip (Rectangle rect
)
1441 Status status
= GDIPlus
.GdipSetClipRectI (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, CombineMode
.Exclude
);
1442 GDIPlus
.CheckStatus (status
);
1445 public void ExcludeClip (Region region
)
1448 throw new ArgumentNullException ("region");
1449 Status status
= GDIPlus
.GdipSetClipRegion (nativeObject
, region
.NativeObject
, CombineMode
.Exclude
);
1450 GDIPlus
.CheckStatus (status
);
1454 public void FillClosedCurve (Brush brush
, PointF
[] points
)
1457 throw new ArgumentNullException ("brush");
1459 throw new ArgumentNullException ("points");
1460 Status status
= GDIPlus
.GdipFillClosedCurve (nativeObject
, brush
.NativeBrush
, points
, points
.Length
);
1461 GDIPlus
.CheckStatus (status
);
1464 public void FillClosedCurve (Brush brush
, Point
[] points
)
1467 throw new ArgumentNullException ("brush");
1469 throw new ArgumentNullException ("points");
1470 Status status
= GDIPlus
.GdipFillClosedCurveI (nativeObject
, brush
.NativeBrush
, points
, points
.Length
);
1471 GDIPlus
.CheckStatus (status
);
1475 public void FillClosedCurve (Brush brush
, PointF
[] points
, FillMode fillmode
)
1478 throw new ArgumentNullException ("brush");
1480 throw new ArgumentNullException ("points");
1481 FillClosedCurve (brush
, points
, fillmode
, 0.5f
);
1484 public void FillClosedCurve (Brush brush
, Point
[] points
, FillMode fillmode
)
1487 throw new ArgumentNullException ("brush");
1489 throw new ArgumentNullException ("points");
1490 FillClosedCurve (brush
, points
, fillmode
, 0.5f
);
1493 public void FillClosedCurve (Brush brush
, PointF
[] points
, FillMode fillmode
, float tension
)
1496 throw new ArgumentNullException ("brush");
1498 throw new ArgumentNullException ("points");
1499 Status status
= GDIPlus
.GdipFillClosedCurve2 (nativeObject
, brush
.NativeBrush
, points
, points
.Length
, tension
, fillmode
);
1500 GDIPlus
.CheckStatus (status
);
1503 public void FillClosedCurve (Brush brush
, Point
[] points
, FillMode fillmode
, float tension
)
1506 throw new ArgumentNullException ("brush");
1508 throw new ArgumentNullException ("points");
1509 Status status
= GDIPlus
.GdipFillClosedCurve2I (nativeObject
, brush
.NativeBrush
, points
, points
.Length
, tension
, fillmode
);
1510 GDIPlus
.CheckStatus (status
);
1513 public void FillEllipse (Brush brush
, Rectangle rect
)
1516 throw new ArgumentNullException ("brush");
1517 FillEllipse (brush
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
1520 public void FillEllipse (Brush brush
, RectangleF rect
)
1523 throw new ArgumentNullException ("brush");
1524 FillEllipse (brush
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
);
1527 public void FillEllipse (Brush brush
, float x
, float y
, float width
, float height
)
1530 throw new ArgumentNullException ("brush");
1531 Status status
= GDIPlus
.GdipFillEllipse (nativeObject
, brush
.NativeBrush
, x
, y
, width
, height
);
1532 GDIPlus
.CheckStatus (status
);
1535 public void FillEllipse (Brush brush
, int x
, int y
, int width
, int height
)
1538 throw new ArgumentNullException ("brush");
1539 Status status
= GDIPlus
.GdipFillEllipseI (nativeObject
, brush
.NativeBrush
, x
, y
, width
, height
);
1540 GDIPlus
.CheckStatus (status
);
1543 public void FillPath (Brush brush
, GraphicsPath path
)
1546 throw new ArgumentNullException ("brush");
1548 throw new ArgumentNullException ("path");
1549 Status status
= GDIPlus
.GdipFillPath (nativeObject
, brush
.NativeBrush
, path
.nativePath
);
1550 GDIPlus
.CheckStatus (status
);
1553 public void FillPie (Brush brush
, Rectangle rect
, float startAngle
, float sweepAngle
)
1556 throw new ArgumentNullException ("brush");
1557 Status status
= GDIPlus
.GdipFillPie (nativeObject
, brush
.NativeBrush
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, startAngle
, sweepAngle
);
1558 GDIPlus
.CheckStatus (status
);
1561 public void FillPie (Brush brush
, int x
, int y
, int width
, int height
, int startAngle
, int sweepAngle
)
1564 throw new ArgumentNullException ("brush");
1565 Status status
= GDIPlus
.GdipFillPieI (nativeObject
, brush
.NativeBrush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1566 GDIPlus
.CheckStatus (status
);
1569 public void FillPie (Brush brush
, float x
, float y
, float width
, float height
, float startAngle
, float sweepAngle
)
1572 throw new ArgumentNullException ("brush");
1573 Status status
= GDIPlus
.GdipFillPie (nativeObject
, brush
.NativeBrush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1574 GDIPlus
.CheckStatus (status
);
1577 public void FillPolygon (Brush brush
, PointF
[] points
)
1580 throw new ArgumentNullException ("brush");
1582 throw new ArgumentNullException ("points");
1583 Status status
= GDIPlus
.GdipFillPolygon2 (nativeObject
, brush
.NativeBrush
, points
, points
.Length
);
1584 GDIPlus
.CheckStatus (status
);
1587 public void FillPolygon (Brush brush
, Point
[] points
)
1590 throw new ArgumentNullException ("brush");
1592 throw new ArgumentNullException ("points");
1593 Status status
= GDIPlus
.GdipFillPolygon2I (nativeObject
, brush
.NativeBrush
, points
, points
.Length
);
1594 GDIPlus
.CheckStatus (status
);
1597 public void FillPolygon (Brush brush
, Point
[] points
, FillMode fillMode
)
1600 throw new ArgumentNullException ("brush");
1602 throw new ArgumentNullException ("points");
1603 Status status
= GDIPlus
.GdipFillPolygonI (nativeObject
, brush
.NativeBrush
, points
, points
.Length
, fillMode
);
1604 GDIPlus
.CheckStatus (status
);
1607 public void FillPolygon (Brush brush
, PointF
[] points
, FillMode fillMode
)
1610 throw new ArgumentNullException ("brush");
1612 throw new ArgumentNullException ("points");
1613 Status status
= GDIPlus
.GdipFillPolygon (nativeObject
, brush
.NativeBrush
, points
, points
.Length
, fillMode
);
1614 GDIPlus
.CheckStatus (status
);
1617 public void FillRectangle (Brush brush
, RectangleF rect
)
1620 throw new ArgumentNullException ("brush");
1621 FillRectangle (brush
, rect
.Left
, rect
.Top
, rect
.Width
, rect
.Height
);
1624 public void FillRectangle (Brush brush
, Rectangle rect
)
1627 throw new ArgumentNullException ("brush");
1629 throw new ArgumentNullException ("rect");
1631 FillRectangle (brush
, rect
.Left
, rect
.Top
, rect
.Width
, rect
.Height
);
1634 public void FillRectangle (Brush brush
, int x
, int y
, int width
, int height
)
1637 throw new ArgumentNullException ("brush");
1639 Status status
= GDIPlus
.GdipFillRectangleI (nativeObject
, brush
.NativeBrush
, x
, y
, width
, height
);
1640 GDIPlus
.CheckStatus (status
);
1643 public void FillRectangle (Brush brush
, float x
, float y
, float width
, float height
)
1646 throw new ArgumentNullException ("brush");
1648 Status status
= GDIPlus
.GdipFillRectangle (nativeObject
, brush
.NativeBrush
, x
, y
, width
, height
);
1649 GDIPlus
.CheckStatus (status
);
1652 public void FillRectangles (Brush brush
, Rectangle
[] rects
)
1655 throw new ArgumentNullException ("brush");
1657 throw new ArgumentNullException ("rects");
1659 Status status
= GDIPlus
.GdipFillRectanglesI (nativeObject
, brush
.NativeBrush
, rects
, rects
.Length
);
1660 GDIPlus
.CheckStatus (status
);
1663 public void FillRectangles (Brush brush
, RectangleF
[] rects
)
1666 throw new ArgumentNullException ("brush");
1668 throw new ArgumentNullException ("rects");
1670 Status status
= GDIPlus
.GdipFillRectangles (nativeObject
, brush
.NativeBrush
, rects
, rects
.Length
);
1671 GDIPlus
.CheckStatus (status
);
1675 public void FillRegion (Brush brush
, Region region
)
1678 throw new ArgumentNullException ("brush");
1680 throw new ArgumentNullException ("region");
1682 Status status
= GDIPlus
.GdipFillRegion (nativeObject
, brush
.NativeBrush
, region
.NativeObject
);
1683 GDIPlus
.CheckStatus(status
);
1687 public void Flush ()
1689 Flush (FlushIntention
.Flush
);
1693 public void Flush (FlushIntention intention
)
1695 if (nativeObject
== IntPtr
.Zero
) {
1699 Status status
= GDIPlus
.GdipFlush (nativeObject
, intention
);
1700 GDIPlus
.CheckStatus (status
);
1702 if (maccontext
!= null)
1703 maccontext
.Synchronize ();
1706 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1707 public static Graphics
FromHdc (IntPtr hdc
)
1710 Status status
= GDIPlus
.GdipCreateFromHDC (hdc
, out graphics
);
1711 GDIPlus
.CheckStatus (status
);
1712 return new Graphics (graphics
);
1716 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1717 public static Graphics
FromHdc (IntPtr hdc
, IntPtr hdevice
)
1719 throw new NotImplementedException ();
1722 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1723 public static Graphics
FromHdcInternal (IntPtr hdc
)
1725 GDIPlus
.Display
= hdc
;
1729 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1730 public static Graphics
FromHwnd (IntPtr hwnd
)
1734 if (GDIPlus
.UseCocoaDrawable
) {
1735 if (hwnd
== IntPtr
.Zero
) {
1736 throw new NotSupportedException ("Opening display graphics is not supported");
1739 CocoaContext context
= MacSupport
.GetCGContextForNSView (hwnd
);
1740 GDIPlus
.GdipCreateFromContext_macosx (context
.ctx
, context
.width
, context
.height
, out graphics
);
1742 Graphics g
= new Graphics (graphics
);
1743 g
.maccontext
= context
;
1748 if (GDIPlus
.UseCarbonDrawable
) {
1749 CarbonContext context
= MacSupport
.GetCGContextForView (hwnd
);
1750 GDIPlus
.GdipCreateFromContext_macosx (context
.ctx
, context
.width
, context
.height
, out graphics
);
1752 Graphics g
= new Graphics (graphics
);
1753 g
.maccontext
= context
;
1757 if (GDIPlus
.UseX11Drawable
) {
1758 if (GDIPlus
.Display
== IntPtr
.Zero
) {
1759 GDIPlus
.Display
= GDIPlus
.XOpenDisplay (IntPtr
.Zero
);
1760 if (GDIPlus
.Display
== IntPtr
.Zero
)
1761 throw new NotSupportedException ("Could not open display (X-Server required. Check your DISPLAY environment variable)");
1763 if (hwnd
== IntPtr
.Zero
) {
1764 hwnd
= GDIPlus
.XRootWindow (GDIPlus
.Display
, GDIPlus
.XDefaultScreen (GDIPlus
.Display
));
1767 return FromXDrawable (hwnd
, GDIPlus
.Display
);
1771 Status status
= GDIPlus
.GdipCreateFromHWND (hwnd
, out graphics
);
1772 GDIPlus
.CheckStatus (status
);
1774 return new Graphics (graphics
);
1777 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
1778 public static Graphics
FromHwndInternal (IntPtr hwnd
)
1780 return FromHwnd (hwnd
);
1783 public static Graphics
FromImage (Image image
)
1788 throw new ArgumentNullException ("image");
1790 if ((image
.PixelFormat
& PixelFormat
.Indexed
) != 0)
1791 throw new Exception (Locale
.GetText ("Cannot create Graphics from an indexed bitmap."));
1793 Status status
= GDIPlus
.GdipGetImageGraphicsContext (image
.nativeObject
, out graphics
);
1794 GDIPlus
.CheckStatus (status
);
1795 Graphics result
= new Graphics (graphics
, image
);
1796 if (GDIPlus
.RunningOnUnix ()) {
1797 Rectangle rect
= new Rectangle (0,0, image
.Width
, image
.Height
);
1798 GDIPlus
.GdipSetVisibleClip_linux (result
.NativeObject
, ref rect
);
1804 internal static Graphics
FromXDrawable (IntPtr drawable
, IntPtr display
)
1808 Status s
= GDIPlus
.GdipCreateFromXDrawable_linux (drawable
, display
, out graphics
);
1809 GDIPlus
.CheckStatus (s
);
1810 return new Graphics (graphics
);
1814 public static IntPtr
GetHalftonePalette ()
1816 throw new NotImplementedException ();
1819 public IntPtr
GetHdc ()
1821 GDIPlus
.CheckStatus (GDIPlus
.GdipGetDC (this.nativeObject
, out deviceContextHdc
));
1822 return deviceContextHdc
;
1825 public Color
GetNearestColor (Color color
)
1829 Status status
= GDIPlus
.GdipGetNearestColor (nativeObject
, out argb
);
1830 GDIPlus
.CheckStatus (status
);
1832 return Color
.FromArgb (argb
);
1836 public void IntersectClip (Region region
)
1839 throw new ArgumentNullException ("region");
1840 Status status
= GDIPlus
.GdipSetClipRegion (nativeObject
, region
.NativeObject
, CombineMode
.Intersect
);
1841 GDIPlus
.CheckStatus (status
);
1844 public void IntersectClip (RectangleF rect
)
1846 Status status
= GDIPlus
.GdipSetClipRect (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, CombineMode
.Intersect
);
1847 GDIPlus
.CheckStatus (status
);
1850 public void IntersectClip (Rectangle rect
)
1852 Status status
= GDIPlus
.GdipSetClipRectI (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, CombineMode
.Intersect
);
1853 GDIPlus
.CheckStatus (status
);
1856 public bool IsVisible (Point point
)
1858 bool isVisible
= false;
1860 Status status
= GDIPlus
.GdipIsVisiblePointI (nativeObject
, point
.X
, point
.Y
, out isVisible
);
1861 GDIPlus
.CheckStatus (status
);
1867 public bool IsVisible (RectangleF rect
)
1869 bool isVisible
= false;
1871 Status status
= GDIPlus
.GdipIsVisibleRect (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, out isVisible
);
1872 GDIPlus
.CheckStatus (status
);
1877 public bool IsVisible (PointF point
)
1879 bool isVisible
= false;
1881 Status status
= GDIPlus
.GdipIsVisiblePoint (nativeObject
, point
.X
, point
.Y
, out isVisible
);
1882 GDIPlus
.CheckStatus (status
);
1887 public bool IsVisible (Rectangle rect
)
1889 bool isVisible
= false;
1891 Status status
= GDIPlus
.GdipIsVisibleRectI (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, out isVisible
);
1892 GDIPlus
.CheckStatus (status
);
1897 public bool IsVisible (float x
, float y
)
1899 return IsVisible (new PointF (x
, y
));
1902 public bool IsVisible (int x
, int y
)
1904 return IsVisible (new Point (x
, y
));
1907 public bool IsVisible (float x
, float y
, float width
, float height
)
1909 return IsVisible (new RectangleF (x
, y
, width
, height
));
1913 public bool IsVisible (int x
, int y
, int width
, int height
)
1915 return IsVisible (new Rectangle (x
, y
, width
, height
));
1919 public Region
[] MeasureCharacterRanges (string text
, Font font
, RectangleF layoutRect
, StringFormat stringFormat
)
1921 if ((text
== null) || (text
.Length
== 0))
1922 return new Region
[0];
1925 throw new ArgumentNullException ("font");
1927 if (stringFormat
== null)
1928 throw new ArgumentException ("stringFormat");
1930 int regcount
= stringFormat
.GetMeasurableCharacterRangeCount ();
1932 return new Region
[0];
1934 IntPtr
[] native_regions
= new IntPtr
[regcount
];
1935 Region
[] regions
= new Region
[regcount
];
1937 for (int i
= 0; i
< regcount
; i
++) {
1938 regions
[i
] = new Region ();
1939 native_regions
[i
] = regions
[i
].NativeObject
;
1942 Status status
= GDIPlus
.GdipMeasureCharacterRanges (nativeObject
, text
, text
.Length
,
1943 font
.NativeObject
, ref layoutRect
, stringFormat
.NativeObject
, regcount
, out native_regions
[0]);
1944 GDIPlus
.CheckStatus (status
);
1949 private unsafe SizeF
GdipMeasureString (IntPtr graphics
, string text
, Font font
, ref RectangleF layoutRect
,
1950 IntPtr stringFormat
)
1952 if ((text
== null) || (text
.Length
== 0))
1956 throw new ArgumentNullException ("font");
1958 RectangleF boundingBox
= new RectangleF ();
1960 Status status
= GDIPlus
.GdipMeasureString (nativeObject
, text
, text
.Length
, font
.NativeObject
,
1961 ref layoutRect
, stringFormat
, out boundingBox
, null, null);
1962 GDIPlus
.CheckStatus (status
);
1964 return new SizeF (boundingBox
.Width
, boundingBox
.Height
);
1967 public SizeF
MeasureString (string text
, Font font
)
1969 return MeasureString (text
, font
, SizeF
.Empty
);
1972 public SizeF
MeasureString (string text
, Font font
, SizeF layoutArea
)
1974 RectangleF rect
= new RectangleF (0, 0, layoutArea
.Width
, layoutArea
.Height
);
1975 return GdipMeasureString (nativeObject
, text
, font
, ref rect
, IntPtr
.Zero
);
1978 public SizeF
MeasureString (string text
, Font font
, int width
)
1980 RectangleF rect
= new RectangleF (0, 0, width
, Int32
.MaxValue
);
1981 return GdipMeasureString (nativeObject
, text
, font
, ref rect
, IntPtr
.Zero
);
1984 public SizeF
MeasureString (string text
, Font font
, SizeF layoutArea
, StringFormat stringFormat
)
1986 RectangleF rect
= new RectangleF (0, 0, layoutArea
.Width
, layoutArea
.Height
);
1987 IntPtr format
= (stringFormat
== null) ? IntPtr
.Zero
: stringFormat
.NativeObject
;
1988 return GdipMeasureString (nativeObject
, text
, font
, ref rect
, format
);
1991 public SizeF
MeasureString (string text
, Font font
, int width
, StringFormat format
)
1993 RectangleF rect
= new RectangleF (0, 0, width
, Int32
.MaxValue
);
1994 IntPtr stringFormat
= (format
== null) ? IntPtr
.Zero
: format
.NativeObject
;
1995 return GdipMeasureString (nativeObject
, text
, font
, ref rect
, stringFormat
);
1998 public SizeF
MeasureString (string text
, Font font
, PointF origin
, StringFormat stringFormat
)
2000 RectangleF rect
= new RectangleF (origin
.X
, origin
.Y
, 0, 0);
2001 IntPtr format
= (stringFormat
== null) ? IntPtr
.Zero
: stringFormat
.NativeObject
;
2002 return GdipMeasureString (nativeObject
, text
, font
, ref rect
, format
);
2005 public SizeF
MeasureString (string text
, Font font
, SizeF layoutArea
, StringFormat stringFormat
,
2006 out int charactersFitted
, out int linesFilled
)
2008 charactersFitted
= 0;
2011 if ((text
== null) || (text
.Length
== 0))
2015 throw new ArgumentNullException ("font");
2017 RectangleF boundingBox
= new RectangleF ();
2018 RectangleF rect
= new RectangleF (0, 0, layoutArea
.Width
, layoutArea
.Height
);
2020 IntPtr format
= (stringFormat
== null) ? IntPtr
.Zero
: stringFormat
.NativeObject
;
2023 fixed (int* pc
= &charactersFitted
, pl
= &linesFilled
) {
2024 Status status
= GDIPlus
.GdipMeasureString (nativeObject
, text
, text
.Length
,
2025 font
.NativeObject
, ref rect
, format
, out boundingBox
, pc
, pl
);
2026 GDIPlus
.CheckStatus (status
);
2029 return new SizeF (boundingBox
.Width
, boundingBox
.Height
);
2032 public void MultiplyTransform (Matrix matrix
)
2034 MultiplyTransform (matrix
, MatrixOrder
.Prepend
);
2037 public void MultiplyTransform (Matrix matrix
, MatrixOrder order
)
2040 throw new ArgumentNullException ("matrix");
2042 Status status
= GDIPlus
.GdipMultiplyWorldTransform (nativeObject
, matrix
.nativeMatrix
, order
);
2043 GDIPlus
.CheckStatus (status
);
2046 [EditorBrowsable (EditorBrowsableState
.Advanced
)]
2047 public void ReleaseHdc (IntPtr hdc
)
2049 ReleaseHdcInternal (hdc
);
2052 public void ReleaseHdc ()
2054 ReleaseHdcInternal (deviceContextHdc
);
2057 [MonoLimitation ("Can only be used when hdc was provided by Graphics.GetHdc() method")]
2058 [EditorBrowsable (EditorBrowsableState
.Never
)]
2059 public void ReleaseHdcInternal (IntPtr hdc
)
2061 Status status
= Status
.InvalidParameter
;
2062 if (hdc
== deviceContextHdc
) {
2063 status
= GDIPlus
.GdipReleaseDC (nativeObject
, deviceContextHdc
);
2064 deviceContextHdc
= IntPtr
.Zero
;
2066 GDIPlus
.CheckStatus (status
);
2069 public void ResetClip ()
2071 Status status
= GDIPlus
.GdipResetClip (nativeObject
);
2072 GDIPlus
.CheckStatus (status
);
2075 public void ResetTransform ()
2077 Status status
= GDIPlus
.GdipResetWorldTransform (nativeObject
);
2078 GDIPlus
.CheckStatus (status
);
2081 public void Restore (GraphicsState gstate
)
2083 // the possible NRE thrown by gstate.nativeState match MS behaviour
2084 Status status
= GDIPlus
.GdipRestoreGraphics (nativeObject
, (uint)gstate
.nativeState
);
2085 GDIPlus
.CheckStatus (status
);
2088 public void RotateTransform (float angle
)
2090 RotateTransform (angle
, MatrixOrder
.Prepend
);
2093 public void RotateTransform (float angle
, MatrixOrder order
)
2095 Status status
= GDIPlus
.GdipRotateWorldTransform (nativeObject
, angle
, order
);
2096 GDIPlus
.CheckStatus (status
);
2099 public GraphicsState
Save ()
2102 Status status
= GDIPlus
.GdipSaveGraphics (nativeObject
, out saveState
);
2103 GDIPlus
.CheckStatus (status
);
2105 GraphicsState state
= new GraphicsState ((int)saveState
);
2109 public void ScaleTransform (float sx
, float sy
)
2111 ScaleTransform (sx
, sy
, MatrixOrder
.Prepend
);
2114 public void ScaleTransform (float sx
, float sy
, MatrixOrder order
)
2116 Status status
= GDIPlus
.GdipScaleWorldTransform (nativeObject
, sx
, sy
, order
);
2117 GDIPlus
.CheckStatus (status
);
2121 public void SetClip (RectangleF rect
)
2123 SetClip (rect
, CombineMode
.Replace
);
2127 public void SetClip (GraphicsPath path
)
2129 SetClip (path
, CombineMode
.Replace
);
2133 public void SetClip (Rectangle rect
)
2135 SetClip (rect
, CombineMode
.Replace
);
2139 public void SetClip (Graphics g
)
2141 SetClip (g
, CombineMode
.Replace
);
2145 public void SetClip (Graphics g
, CombineMode combineMode
)
2148 throw new ArgumentNullException ("g");
2150 Status status
= GDIPlus
.GdipSetClipGraphics (nativeObject
, g
.NativeObject
, combineMode
);
2151 GDIPlus
.CheckStatus (status
);
2155 public void SetClip (Rectangle rect
, CombineMode combineMode
)
2157 Status status
= GDIPlus
.GdipSetClipRectI (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, combineMode
);
2158 GDIPlus
.CheckStatus (status
);
2162 public void SetClip (RectangleF rect
, CombineMode combineMode
)
2164 Status status
= GDIPlus
.GdipSetClipRect (nativeObject
, rect
.X
, rect
.Y
, rect
.Width
, rect
.Height
, combineMode
);
2165 GDIPlus
.CheckStatus (status
);
2169 public void SetClip (Region region
, CombineMode combineMode
)
2172 throw new ArgumentNullException ("region");
2173 Status status
= GDIPlus
.GdipSetClipRegion(nativeObject
, region
.NativeObject
, combineMode
);
2174 GDIPlus
.CheckStatus (status
);
2178 public void SetClip (GraphicsPath path
, CombineMode combineMode
)
2181 throw new ArgumentNullException ("path");
2182 Status status
= GDIPlus
.GdipSetClipPath (nativeObject
, path
.nativePath
, combineMode
);
2183 GDIPlus
.CheckStatus (status
);
2187 public void TransformPoints (CoordinateSpace destSpace
, CoordinateSpace srcSpace
, PointF
[] pts
)
2190 throw new ArgumentNullException ("pts");
2192 IntPtr ptrPt
= GDIPlus
.FromPointToUnManagedMemory (pts
);
2194 Status status
= GDIPlus
.GdipTransformPoints (nativeObject
, destSpace
, srcSpace
, ptrPt
, pts
.Length
);
2195 GDIPlus
.CheckStatus (status
);
2197 GDIPlus
.FromUnManagedMemoryToPoint (ptrPt
, pts
);
2201 public void TransformPoints (CoordinateSpace destSpace
, CoordinateSpace srcSpace
, Point
[] pts
)
2204 throw new ArgumentNullException ("pts");
2205 IntPtr ptrPt
= GDIPlus
.FromPointToUnManagedMemoryI (pts
);
2207 Status status
= GDIPlus
.GdipTransformPointsI (nativeObject
, destSpace
, srcSpace
, ptrPt
, pts
.Length
);
2208 GDIPlus
.CheckStatus (status
);
2210 GDIPlus
.FromUnManagedMemoryToPointI (ptrPt
, pts
);
2214 public void TranslateClip (int dx
, int dy
)
2216 Status status
= GDIPlus
.GdipTranslateClipI (nativeObject
, dx
, dy
);
2217 GDIPlus
.CheckStatus (status
);
2221 public void TranslateClip (float dx
, float dy
)
2223 Status status
= GDIPlus
.GdipTranslateClip (nativeObject
, dx
, dy
);
2224 GDIPlus
.CheckStatus (status
);
2227 public void TranslateTransform (float dx
, float dy
)
2229 TranslateTransform (dx
, dy
, MatrixOrder
.Prepend
);
2233 public void TranslateTransform (float dx
, float dy
, MatrixOrder order
)
2235 Status status
= GDIPlus
.GdipTranslateWorldTransform (nativeObject
, dx
, dy
, order
);
2236 GDIPlus
.CheckStatus (status
);
2239 public Region Clip
{
2241 Region reg
= new Region();
2242 Status status
= GDIPlus
.GdipGetClip (nativeObject
, reg
.NativeObject
);
2243 GDIPlus
.CheckStatus (status
);
2247 SetClip (value, CombineMode
.Replace
);
2251 public RectangleF ClipBounds
{
2253 RectangleF rect
= new RectangleF ();
2254 Status status
= GDIPlus
.GdipGetClipBounds (nativeObject
, out rect
);
2255 GDIPlus
.CheckStatus (status
);
2260 public CompositingMode CompositingMode
{
2262 CompositingMode mode
;
2263 Status status
= GDIPlus
.GdipGetCompositingMode (nativeObject
, out mode
);
2264 GDIPlus
.CheckStatus (status
);
2269 Status status
= GDIPlus
.GdipSetCompositingMode (nativeObject
, value);
2270 GDIPlus
.CheckStatus (status
);
2275 public CompositingQuality CompositingQuality
{
2277 CompositingQuality quality
;
2279 Status status
= GDIPlus
.GdipGetCompositingQuality (nativeObject
, out quality
);
2280 GDIPlus
.CheckStatus (status
);
2284 Status status
= GDIPlus
.GdipSetCompositingQuality (nativeObject
, value);
2285 GDIPlus
.CheckStatus (status
);
2293 Status status
= GDIPlus
.GdipGetDpiX (nativeObject
, out x
);
2294 GDIPlus
.CheckStatus (status
);
2303 Status status
= GDIPlus
.GdipGetDpiY (nativeObject
, out y
);
2304 GDIPlus
.CheckStatus (status
);
2309 public InterpolationMode InterpolationMode
{
2311 InterpolationMode imode
= InterpolationMode
.Invalid
;
2312 Status status
= GDIPlus
.GdipGetInterpolationMode (nativeObject
, out imode
);
2313 GDIPlus
.CheckStatus (status
);
2317 Status status
= GDIPlus
.GdipSetInterpolationMode (nativeObject
, value);
2318 GDIPlus
.CheckStatus (status
);
2322 public bool IsClipEmpty
{
2324 bool isEmpty
= false;
2326 Status status
= GDIPlus
.GdipIsClipEmpty (nativeObject
, out isEmpty
);
2327 GDIPlus
.CheckStatus (status
);
2332 public bool IsVisibleClipEmpty
{
2334 bool isEmpty
= false;
2336 Status status
= GDIPlus
.GdipIsVisibleClipEmpty (nativeObject
, out isEmpty
);
2337 GDIPlus
.CheckStatus (status
);
2342 public float PageScale
{
2346 Status status
= GDIPlus
.GdipGetPageScale (nativeObject
, out scale
);
2347 GDIPlus
.CheckStatus (status
);
2351 Status status
= GDIPlus
.GdipSetPageScale (nativeObject
, value);
2352 GDIPlus
.CheckStatus (status
);
2356 public GraphicsUnit PageUnit
{
2360 Status status
= GDIPlus
.GdipGetPageUnit (nativeObject
, out unit
);
2361 GDIPlus
.CheckStatus (status
);
2365 Status status
= GDIPlus
.GdipSetPageUnit (nativeObject
, value);
2366 GDIPlus
.CheckStatus (status
);
2370 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2371 public PixelOffsetMode PixelOffsetMode
{
2373 PixelOffsetMode pixelOffset
= PixelOffsetMode
.Invalid
;
2375 Status status
= GDIPlus
.GdipGetPixelOffsetMode (nativeObject
, out pixelOffset
);
2376 GDIPlus
.CheckStatus (status
);
2380 Status status
= GDIPlus
.GdipSetPixelOffsetMode (nativeObject
, value);
2381 GDIPlus
.CheckStatus (status
);
2385 public Point RenderingOrigin
{
2388 Status status
= GDIPlus
.GdipGetRenderingOrigin (nativeObject
, out x
, out y
);
2389 GDIPlus
.CheckStatus (status
);
2390 return new Point (x
, y
);
2394 Status status
= GDIPlus
.GdipSetRenderingOrigin (nativeObject
, value.X
, value.Y
);
2395 GDIPlus
.CheckStatus (status
);
2399 public SmoothingMode SmoothingMode
{
2401 SmoothingMode mode
= SmoothingMode
.Invalid
;
2403 Status status
= GDIPlus
.GdipGetSmoothingMode (nativeObject
, out mode
);
2404 GDIPlus
.CheckStatus (status
);
2409 Status status
= GDIPlus
.GdipSetSmoothingMode (nativeObject
, value);
2410 GDIPlus
.CheckStatus (status
);
2414 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2415 public int TextContrast
{
2419 Status status
= GDIPlus
.GdipGetTextContrast (nativeObject
, out contrast
);
2420 GDIPlus
.CheckStatus (status
);
2425 Status status
= GDIPlus
.GdipSetTextContrast (nativeObject
, value);
2426 GDIPlus
.CheckStatus (status
);
2430 public TextRenderingHint TextRenderingHint
{
2432 TextRenderingHint hint
;
2434 Status status
= GDIPlus
.GdipGetTextRenderingHint (nativeObject
, out hint
);
2435 GDIPlus
.CheckStatus (status
);
2440 Status status
= GDIPlus
.GdipSetTextRenderingHint (nativeObject
, value);
2441 GDIPlus
.CheckStatus (status
);
2445 public Matrix Transform
{
2447 Matrix matrix
= new Matrix ();
2448 Status status
= GDIPlus
.GdipGetWorldTransform (nativeObject
, matrix
.nativeMatrix
);
2449 GDIPlus
.CheckStatus (status
);
2454 throw new ArgumentNullException ("value");
2456 Status status
= GDIPlus
.GdipSetWorldTransform (nativeObject
, value.nativeMatrix
);
2457 GDIPlus
.CheckStatus (status
);
2461 public RectangleF VisibleClipBounds
{
2465 Status status
= GDIPlus
.GdipGetVisibleClipBounds (nativeObject
, out rect
);
2466 GDIPlus
.CheckStatus (status
);
2472 [EditorBrowsable (EditorBrowsableState
.Never
)]
2473 public object GetContextInfo ()
2475 // only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
2476 throw new NotImplementedException ();