fix typo
[mcs.git] / class / System.Drawing / System.Drawing / Graphics.cs
blob48a379b6461cc053daebf39283f6a1ef994b0b7d
1 //
2 // System.Drawing.Graphics.cs
3 //
4 // Authors:
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>
9 //
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:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
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;
39 using System.Text;
41 namespace System.Drawing
43 #if !NET_2_0
44 [ComVisible(false)]
45 #endif
46 public sealed class Graphics : MarshalByRefObject, IDisposable
47 #if NET_2_0
48 , IDeviceContext
49 #endif
51 internal IntPtr nativeObject = IntPtr.Zero;
52 internal CarbonContext context;
53 private bool disposed = false;
54 private static float defDpiX = 0;
55 private static float defDpiY = 0;
56 private IntPtr deviceContextHdc;
58 #if !NET_2_0
59 [ComVisible(false)]
60 #endif
61 public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
62 int flags,
63 int dataSize,
64 IntPtr data,
65 PlayRecordCallback callbackData);
67 #if !NET_2_0
68 [ComVisible (false)]
69 #endif
70 public delegate bool DrawImageAbort (IntPtr callbackData);
72 internal Graphics (IntPtr nativeGraphics)
74 nativeObject = nativeGraphics;
77 ~Graphics ()
79 Dispose ();
82 static internal float systemDpiX {
83 get {
84 if (defDpiX == 0) {
85 Bitmap bmp = new Bitmap (1, 1);
86 Graphics g = Graphics.FromImage (bmp);
87 defDpiX = g.DpiX;
88 defDpiY = g.DpiY;
90 return defDpiX;
94 static internal float systemDpiY {
95 get {
96 if (defDpiY == 0) {
97 Bitmap bmp = new Bitmap (1, 1);
98 Graphics g = Graphics.FromImage (bmp);
99 defDpiX = g.DpiX;
100 defDpiY = g.DpiY;
102 return defDpiY;
106 internal IntPtr NativeObject {
107 get {
108 return nativeObject;
111 set {
112 nativeObject = value;
116 [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
117 public void AddMetafileComment (byte [] data)
119 throw new NotImplementedException ();
122 public GraphicsContainer BeginContainer ()
124 uint state;
125 Status status;
126 status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
127 GDIPlus.CheckStatus (status);
129 return new GraphicsContainer(state);
132 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]
133 public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
135 uint state;
136 Status status;
137 status = GDIPlus.GdipBeginContainerI (nativeObject, ref dstrect, ref srcrect, unit, out state);
138 GDIPlus.CheckStatus (status);
140 return new GraphicsContainer (state);
143 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]
144 public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
146 uint state;
147 Status status;
148 status = GDIPlus.GdipBeginContainer (nativeObject, ref dstrect, ref srcrect, unit, out state);
149 GDIPlus.CheckStatus (status);
151 return new GraphicsContainer (state);
155 public void Clear (Color color)
157 Status status;
158 status = GDIPlus.GdipGraphicsClear (nativeObject, color.ToArgb ());
159 GDIPlus.CheckStatus (status);
161 #if NET_2_0
162 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
163 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
165 CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
166 blockRegionSize, CopyPixelOperation.SourceCopy);
169 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
170 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
172 CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
173 blockRegionSize, copyPixelOperation);
176 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
177 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize)
179 CopyFromScreen (sourceX, sourceY, destinationX, destinationY, blockRegionSize,
180 CopyPixelOperation.SourceCopy);
183 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
184 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
186 if (!Enum.IsDefined (typeof (CopyPixelOperation), copyPixelOperation))
187 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for CopyPixelOperation", copyPixelOperation));
189 if (GDIPlus.UseX11Drawable) {
190 CopyFromScreenX11 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
191 } else if (GDIPlus.UseCarbonDrawable) {
192 CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
193 } else {
194 CopyFromScreenWin32 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
198 private void CopyFromScreenWin32 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
200 IntPtr window = GDIPlus.GetDesktopWindow ();
201 IntPtr srcDC = GDIPlus.GetDC (window);
202 IntPtr dstDC = GetHdc ();
203 GDIPlus.BitBlt (dstDC, destinationX, destinationY, blockRegionSize.Width,
204 blockRegionSize.Height, srcDC, sourceX, sourceY, (int) copyPixelOperation);
206 GDIPlus.ReleaseDC (IntPtr.Zero, srcDC);
207 ReleaseHdc (dstDC);
210 private void CopyFromScreenMac (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
212 throw new NotImplementedException ();
215 private void CopyFromScreenX11 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
217 IntPtr window, image, defvisual, vPtr;
218 int AllPlanes = ~0, nitems = 0, pixel;
220 if (copyPixelOperation != CopyPixelOperation.SourceCopy)
221 throw new NotImplementedException ("Operation not implemented under X11");
223 if (GDIPlus.Display == IntPtr.Zero) {
224 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
227 window = GDIPlus.XRootWindow (GDIPlus.Display, 0);
228 defvisual = GDIPlus.XDefaultVisual (GDIPlus.Display, 0);
229 XVisualInfo visual = new XVisualInfo ();
231 /* Get XVisualInfo for this visual */
232 visual.visualid = GDIPlus.XVisualIDFromVisual(defvisual);
233 vPtr = GDIPlus.XGetVisualInfo (GDIPlus.Display, 0x1 /* VisualIDMask */, ref visual, ref nitems);
234 visual = (XVisualInfo) Marshal.PtrToStructure(vPtr, typeof (XVisualInfo));
235 #if false
236 Console.WriteLine ("visual\t{0}", visual.visual);
237 Console.WriteLine ("visualid\t{0}", visual.visualid);
238 Console.WriteLine ("screen\t{0}", visual.screen);
239 Console.WriteLine ("depth\t{0}", visual.depth);
240 Console.WriteLine ("klass\t{0}", visual.klass);
241 Console.WriteLine ("red_mask\t{0:X}", visual.red_mask);
242 Console.WriteLine ("green_mask\t{0:X}", visual.green_mask);
243 Console.WriteLine ("blue_mask\t{0:X}", visual.blue_mask);
244 Console.WriteLine ("colormap_size\t{0}", visual.colormap_size);
245 Console.WriteLine ("bits_per_rgb\t{0}", visual.bits_per_rgb);
246 #endif
247 image = GDIPlus.XGetImage (GDIPlus.Display, window, sourceX, sourceY, blockRegionSize.Width,
248 blockRegionSize.Height, AllPlanes, 2 /* ZPixmap*/);
250 Bitmap bmp = new Bitmap (blockRegionSize.Width, blockRegionSize.Height);
251 int red, blue, green;
252 int red_mask = (int) visual.red_mask;
253 int blue_mask = (int) visual.blue_mask;
254 int green_mask = (int) visual.green_mask;
255 for (int y = 0; y < blockRegionSize.Height; y++) {
256 for (int x = 0; x < blockRegionSize.Width; x++) {
257 pixel = GDIPlus.XGetPixel (image, x, y);
259 switch (visual.depth) {
260 case 16: /* 16bbp pixel transformation */
261 red = (int) ((pixel & red_mask ) >> 8) & 0xff;
262 green = (int) (((pixel & green_mask ) >> 3 )) & 0xff;
263 blue = (int) ((pixel & blue_mask ) << 3 ) & 0xff;
264 break;
265 case 24:
266 case 32:
267 red = (int) ((pixel & red_mask ) >> 16) & 0xff;
268 green = (int) (((pixel & green_mask ) >> 8 )) & 0xff;
269 blue = (int) ((pixel & blue_mask )) & 0xff;
270 break;
271 default:
272 string text = Locale.GetText ("{0}bbp depth not supported.", visual.depth);
273 throw new NotImplementedException (text);
276 bmp.SetPixel (x, y, Color.FromArgb (255, red, green, blue));
280 DrawImage (bmp, destinationX, destinationY);
281 bmp.Dispose ();
282 GDIPlus.XDestroyImage (image);
283 GDIPlus.XFree (vPtr);
285 #endif
287 public void Dispose ()
289 Status status;
290 if (! disposed) {
291 if (GDIPlus.UseCarbonDrawable && context.ctx != IntPtr.Zero) {
292 Flush ();
293 Carbon.CGContextSynchronize (context.ctx);
294 Carbon.ReleaseContext (context.port, context.ctx);
296 status = GDIPlus.GdipDeleteGraphics (nativeObject);
297 nativeObject = IntPtr.Zero;
298 GDIPlus.CheckStatus (status);
299 disposed = true;
302 GC.SuppressFinalize(this);
306 public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
308 DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
312 public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
314 DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
318 public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
320 Status status;
321 if (pen == null)
322 throw new ArgumentNullException ("pen");
324 status = GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
325 x, y, width, height, startAngle, sweepAngle);
326 GDIPlus.CheckStatus (status);
329 // Microsoft documentation states that the signature for this member should be
330 // public void DrawArc( Pen pen, int x, int y, int width, int height, int startAngle,
331 // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
332 public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
334 Status status;
335 if (pen == null)
336 throw new ArgumentNullException ("pen");
337 status = GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
338 x, y, width, height, startAngle, sweepAngle);
339 GDIPlus.CheckStatus (status);
342 public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
344 Status status;
345 if (pen == null)
346 throw new ArgumentNullException ("pen");
347 status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
348 pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
349 pt3.Y, pt4.X, pt4.Y);
350 GDIPlus.CheckStatus (status);
353 public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
355 Status status;
356 if (pen == null)
357 throw new ArgumentNullException ("pen");
358 status = GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject,
359 pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
360 pt3.Y, pt4.X, pt4.Y);
361 GDIPlus.CheckStatus (status);
364 public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
366 Status status;
367 if (pen == null)
368 throw new ArgumentNullException ("pen");
369 status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1,
370 y1, x2, y2, x3, y3, x4, y4);
371 GDIPlus.CheckStatus (status);
374 public void DrawBeziers (Pen pen, Point [] points)
376 if (pen == null)
377 throw new ArgumentNullException ("pen");
378 if (points == null)
379 throw new ArgumentNullException ("points");
381 int length = points.Length;
382 Status status;
384 if (length < 4)
385 return;
387 for (int i = 0; i < length - 1; i += 3) {
388 Point p1 = points [i];
389 Point p2 = points [i + 1];
390 Point p3 = points [i + 2];
391 Point p4 = points [i + 3];
393 status = GDIPlus.GdipDrawBezier (nativeObject,
394 pen.nativeObject,
395 p1.X, p1.Y, p2.X, p2.Y,
396 p3.X, p3.Y, p4.X, p4.Y);
397 GDIPlus.CheckStatus (status);
401 public void DrawBeziers (Pen pen, PointF [] points)
403 if (pen == null)
404 throw new ArgumentNullException ("pen");
405 if (points == null)
406 throw new ArgumentNullException ("points");
408 int length = points.Length;
409 Status status;
411 if (length < 4)
412 return;
414 for (int i = 0; i < length - 1; i += 3) {
415 PointF p1 = points [i];
416 PointF p2 = points [i + 1];
417 PointF p3 = points [i + 2];
418 PointF p4 = points [i + 3];
420 status = GDIPlus.GdipDrawBezier (nativeObject,
421 pen.nativeObject,
422 p1.X, p1.Y, p2.X, p2.Y,
423 p3.X, p3.Y, p4.X, p4.Y);
424 GDIPlus.CheckStatus (status);
429 public void DrawClosedCurve (Pen pen, PointF [] points)
431 if (pen == null)
432 throw new ArgumentNullException ("pen");
433 if (points == null)
434 throw new ArgumentNullException ("points");
436 Status status;
437 status = GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
438 GDIPlus.CheckStatus (status);
441 public void DrawClosedCurve (Pen pen, Point [] points)
443 if (pen == null)
444 throw new ArgumentNullException ("pen");
445 if (points == null)
446 throw new ArgumentNullException ("points");
448 Status status;
449 status = GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);
450 GDIPlus.CheckStatus (status);
453 // according to MSDN fillmode "is required but ignored" which makes _some_ sense since the unmanaged
454 // GDI+ call doesn't support it (issue spotted using Gendarme's AvoidUnusedParametersRule)
455 public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode)
457 if (pen == null)
458 throw new ArgumentNullException ("pen");
459 if (points == null)
460 throw new ArgumentNullException ("points");
462 Status status;
463 status = GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
464 GDIPlus.CheckStatus (status);
467 // according to MSDN fillmode "is required but ignored" which makes _some_ sense since the unmanaged
468 // GDI+ call doesn't support it (issue spotted using Gendarme's AvoidUnusedParametersRule)
469 public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode)
471 if (pen == null)
472 throw new ArgumentNullException ("pen");
473 if (points == null)
474 throw new ArgumentNullException ("points");
476 Status status;
477 status = GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
478 GDIPlus.CheckStatus (status);
481 public void DrawCurve (Pen pen, Point [] points)
483 if (pen == null)
484 throw new ArgumentNullException ("pen");
485 if (points == null)
486 throw new ArgumentNullException ("points");
488 Status status;
489 status = GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);
490 GDIPlus.CheckStatus (status);
493 public void DrawCurve (Pen pen, PointF [] points)
495 if (pen == null)
496 throw new ArgumentNullException ("pen");
497 if (points == null)
498 throw new ArgumentNullException ("points");
500 Status status;
501 status = GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);
502 GDIPlus.CheckStatus (status);
505 public void DrawCurve (Pen pen, PointF [] points, float tension)
507 if (pen == null)
508 throw new ArgumentNullException ("pen");
509 if (points == null)
510 throw new ArgumentNullException ("points");
512 Status status;
513 status = GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
514 GDIPlus.CheckStatus (status);
517 public void DrawCurve (Pen pen, Point [] points, float tension)
519 if (pen == null)
520 throw new ArgumentNullException ("pen");
521 if (points == null)
522 throw new ArgumentNullException ("points");
524 Status status;
525 status = GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
526 GDIPlus.CheckStatus (status);
529 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
531 if (pen == null)
532 throw new ArgumentNullException ("pen");
533 if (points == null)
534 throw new ArgumentNullException ("points");
536 Status status;
537 status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
538 points, points.Length, offset,
539 numberOfSegments, 0.5f);
540 GDIPlus.CheckStatus (status);
543 public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension)
545 if (pen == null)
546 throw new ArgumentNullException ("pen");
547 if (points == null)
548 throw new ArgumentNullException ("points");
550 Status status;
551 status = GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject,
552 points, points.Length, offset,
553 numberOfSegments, tension);
554 GDIPlus.CheckStatus (status);
557 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
559 if (pen == null)
560 throw new ArgumentNullException ("pen");
561 if (points == null)
562 throw new ArgumentNullException ("points");
564 Status status;
565 status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
566 points, points.Length, offset,
567 numberOfSegments, tension);
568 GDIPlus.CheckStatus (status);
571 public void DrawEllipse (Pen pen, Rectangle rect)
573 if (pen == null)
574 throw new ArgumentNullException ("pen");
576 DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
579 public void DrawEllipse (Pen pen, RectangleF rect)
581 if (pen == null)
582 throw new ArgumentNullException ("pen");
583 DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
586 public void DrawEllipse (Pen pen, int x, int y, int width, int height)
588 if (pen == null)
589 throw new ArgumentNullException ("pen");
590 Status status;
591 status = GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
592 GDIPlus.CheckStatus (status);
595 public void DrawEllipse (Pen pen, float x, float y, float width, float height)
597 if (pen == null)
598 throw new ArgumentNullException ("pen");
599 Status status = GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height);
600 GDIPlus.CheckStatus (status);
603 public void DrawIcon (Icon icon, Rectangle targetRect)
605 if (icon == null)
606 throw new ArgumentNullException ("icon");
608 DrawImage (icon.GetInternalBitmap (), targetRect);
611 public void DrawIcon (Icon icon, int x, int y)
613 if (icon == null)
614 throw new ArgumentNullException ("icon");
616 DrawImage (icon.GetInternalBitmap (), x, y);
619 public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
621 if (icon == null)
622 throw new ArgumentNullException ("icon");
624 DrawImageUnscaled (icon.GetInternalBitmap (), targetRect);
627 public void DrawImage (Image image, RectangleF rect)
629 if (image == null)
630 throw new ArgumentNullException ("image");
632 Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y, rect.Width, rect.Height);
633 GDIPlus.CheckStatus (status);
636 public void DrawImage (Image image, PointF point)
638 if (image == null)
639 throw new ArgumentNullException ("image");
641 Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);
642 GDIPlus.CheckStatus (status);
645 public void DrawImage (Image image, Point [] destPoints)
647 if (image == null)
648 throw new ArgumentNullException ("image");
649 if (destPoints == null)
650 throw new ArgumentNullException ("destPoints");
652 Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
653 GDIPlus.CheckStatus (status);
656 public void DrawImage (Image image, Point point)
658 if (image == null)
659 throw new ArgumentNullException ("image");
660 DrawImage (image, point.X, point.Y);
663 public void DrawImage (Image image, Rectangle rect)
665 if (image == null)
666 throw new ArgumentNullException ("image");
667 DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
670 public void DrawImage (Image image, PointF [] destPoints)
672 if (image == null)
673 throw new ArgumentNullException ("image");
674 if (destPoints == null)
675 throw new ArgumentNullException ("destPoints");
676 Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
677 GDIPlus.CheckStatus (status);
680 public void DrawImage (Image image, int x, int y)
682 if (image == null)
683 throw new ArgumentNullException ("image");
684 Status status = GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
685 GDIPlus.CheckStatus (status);
688 public void DrawImage (Image image, float x, float y)
690 if (image == null)
691 throw new ArgumentNullException ("image");
692 Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
693 GDIPlus.CheckStatus (status);
696 public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
698 if (image == null)
699 throw new ArgumentNullException ("image");
700 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
701 destRect.X, destRect.Y, destRect.Width, destRect.Height,
702 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
703 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
704 GDIPlus.CheckStatus (status);
707 public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
709 if (image == null)
710 throw new ArgumentNullException ("image");
711 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
712 destRect.X, destRect.Y, destRect.Width, destRect.Height,
713 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
714 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
715 GDIPlus.CheckStatus (status);
718 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
720 if (image == null)
721 throw new ArgumentNullException ("image");
722 if (destPoints == null)
723 throw new ArgumentNullException ("destPoints");
725 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
726 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
727 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
728 null, IntPtr.Zero);
729 GDIPlus.CheckStatus (status);
732 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
734 if (image == null)
735 throw new ArgumentNullException ("image");
736 if (destPoints == null)
737 throw new ArgumentNullException ("destPoints");
739 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
740 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
741 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero,
742 null, IntPtr.Zero);
743 GDIPlus.CheckStatus (status);
746 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit,
747 ImageAttributes imageAttr)
749 if (image == null)
750 throw new ArgumentNullException ("image");
751 if (destPoints == null)
752 throw new ArgumentNullException ("destPoints");
753 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
754 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
755 srcRect.Width, srcRect.Height, srcUnit,
756 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
757 GDIPlus.CheckStatus (status);
760 public void DrawImage (Image image, float x, float y, float width, float height)
762 if (image == null)
763 throw new ArgumentNullException ("image");
764 Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
765 width, height);
766 GDIPlus.CheckStatus (status);
769 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit,
770 ImageAttributes imageAttr)
772 if (image == null)
773 throw new ArgumentNullException ("image");
774 if (destPoints == null)
775 throw new ArgumentNullException ("destPoints");
776 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
777 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
778 srcRect.Width, srcRect.Height, srcUnit,
779 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
780 GDIPlus.CheckStatus (status);
783 public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
785 if (image == null)
786 throw new ArgumentNullException ("image");
787 Status status = GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
788 GDIPlus.CheckStatus (status);
791 public void DrawImage (Image image, int x, int y, int width, int height)
793 if (image == null)
794 throw new ArgumentNullException ("image");
795 Status status = GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
796 GDIPlus.CheckStatus (status);
799 public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
801 if (image == null)
802 throw new ArgumentNullException ("image");
803 Status status = GDIPlus.GdipDrawImagePointRect (nativeObject, image.nativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
804 GDIPlus.CheckStatus (status);
807 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
809 if (image == null)
810 throw new ArgumentNullException ("image");
811 if (destPoints == null)
812 throw new ArgumentNullException ("destPoints");
813 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
814 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
815 srcRect.Width, srcRect.Height, srcUnit,
816 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
817 GDIPlus.CheckStatus (status);
820 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
822 if (image == null)
823 throw new ArgumentNullException ("image");
824 if (destPoints == null)
825 throw new ArgumentNullException ("destPoints");
827 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
828 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
829 srcRect.Width, srcRect.Height, srcUnit,
830 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
831 GDIPlus.CheckStatus (status);
834 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
836 if (image == null)
837 throw new ArgumentNullException ("image");
838 if (destPoints == null)
839 throw new ArgumentNullException ("destPoints");
841 Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
842 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
843 srcRect.Width, srcRect.Height, srcUnit,
844 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
845 GDIPlus.CheckStatus (status);
848 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
850 if (image == null)
851 throw new ArgumentNullException ("image");
852 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
853 destRect.X, destRect.Y, destRect.Width, destRect.Height,
854 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero,
855 null, IntPtr.Zero);
856 GDIPlus.CheckStatus (status);
859 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
861 Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
862 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
863 srcRect.Width, srcRect.Height, srcUnit,
864 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
865 GDIPlus.CheckStatus (status);
868 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
870 if (image == null)
871 throw new ArgumentNullException ("image");
872 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
873 destRect.X, destRect.Y, destRect.Width, destRect.Height,
874 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero,
875 null, IntPtr.Zero);
876 GDIPlus.CheckStatus (status);
879 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
881 if (image == null)
882 throw new ArgumentNullException ("image");
883 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
884 destRect.X, destRect.Y, destRect.Width, destRect.Height,
885 srcX, srcY, srcWidth, srcHeight, srcUnit,
886 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
887 GDIPlus.CheckStatus (status);
890 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
892 if (image == null)
893 throw new ArgumentNullException ("image");
894 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
895 destRect.X, destRect.Y, destRect.Width,
896 destRect.Height, srcX, srcY, srcWidth, srcHeight,
897 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
898 GDIPlus.CheckStatus (status);
901 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
903 if (image == null)
904 throw new ArgumentNullException ("image");
905 Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
906 destRect.X, destRect.Y, destRect.Width,
907 destRect.Height, srcX, srcY, srcWidth, srcHeight,
908 srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback,
909 IntPtr.Zero);
910 GDIPlus.CheckStatus (status);
913 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback)
915 if (image == null)
916 throw new ArgumentNullException ("image");
917 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
918 destRect.X, destRect.Y, destRect.Width,
919 destRect.Height, srcX, srcY, srcWidth, srcHeight,
920 srcUnit, imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero,
921 callback, IntPtr.Zero);
922 GDIPlus.CheckStatus (status);
925 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
927 if (image == null)
928 throw new ArgumentNullException ("image");
929 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
930 destRect.X, destRect.Y, destRect.Width, destRect.Height,
931 srcX, srcY, srcWidth, srcHeight, srcUnit,
932 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, callback, callbackData);
933 GDIPlus.CheckStatus (status);
936 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
938 if (image == null)
939 throw new ArgumentNullException ("image");
940 Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
941 destRect.X, destRect.Y, destRect.Width, destRect.Height,
942 srcX, srcY, srcWidth, srcHeight, srcUnit,
943 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, callback, callbackData);
944 GDIPlus.CheckStatus (status);
947 public void DrawImageUnscaled (Image image, Point point)
949 DrawImageUnscaled (image, point.X, point.Y);
952 public void DrawImageUnscaled (Image image, Rectangle rect)
954 DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
957 public void DrawImageUnscaled (Image image, int x, int y)
959 if (image == null)
960 throw new ArgumentNullException ("image");
961 DrawImage (image, x, y, image.Width, image.Height);
964 public void DrawImageUnscaled (Image image, int x, int y, int width, int height)
966 if (image == null)
967 throw new ArgumentNullException ("image");
969 // avoid creating an empty, or negative w/h, bitmap...
970 if ((width <= 0) || (height <= 0))
971 return;
973 using (Image tmpImg = new Bitmap (width, height)) {
974 using (Graphics g = FromImage (tmpImg)) {
975 g.DrawImage (image, 0, 0, image.Width, image.Height);
976 DrawImage (tmpImg, x, y, width, height);
981 #if NET_2_0
982 public void DrawImageUnscaledAndClipped (Image image, Rectangle rect)
984 if (image == null)
985 throw new ArgumentNullException ("image");
987 int width = (image.Width > rect.Width) ? rect.Width : image.Width;
988 int height = (image.Height > rect.Height) ? rect.Height : image.Height;
990 DrawImageUnscaled (image, rect.X, rect.Y, width, height);
992 #endif
994 public void DrawLine (Pen pen, PointF pt1, PointF pt2)
996 if (pen == null)
997 throw new ArgumentNullException ("pen");
998 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject,
999 pt1.X, pt1.Y, pt2.X, pt2.Y);
1000 GDIPlus.CheckStatus (status);
1003 public void DrawLine (Pen pen, Point pt1, Point pt2)
1005 if (pen == null)
1006 throw new ArgumentNullException ("pen");
1007 Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject,
1008 pt1.X, pt1.Y, pt2.X, pt2.Y);
1009 GDIPlus.CheckStatus (status);
1012 public void DrawLine (Pen pen, int x1, int y1, int x2, int y2)
1014 if (pen == null)
1015 throw new ArgumentNullException ("pen");
1016 Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);
1017 GDIPlus.CheckStatus (status);
1020 public void DrawLine (Pen pen, float x1, float y1, float x2, float y2)
1022 if (pen == null)
1023 throw new ArgumentNullException ("pen");
1024 Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);
1025 GDIPlus.CheckStatus (status);
1028 public void DrawLines (Pen pen, PointF [] points)
1030 if (pen == null)
1031 throw new ArgumentNullException ("pen");
1032 if (points == null)
1033 throw new ArgumentNullException ("points");
1034 Status status = GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);
1035 GDIPlus.CheckStatus (status);
1038 public void DrawLines (Pen pen, Point [] points)
1040 if (pen == null)
1041 throw new ArgumentNullException ("pen");
1042 if (points == null)
1043 throw new ArgumentNullException ("points");
1044 Status status = GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);
1045 GDIPlus.CheckStatus (status);
1048 public void DrawPath (Pen pen, GraphicsPath path)
1050 if (pen == null)
1051 throw new ArgumentNullException ("pen");
1052 if (path == null)
1053 throw new ArgumentNullException ("path");
1054 Status status = GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
1055 GDIPlus.CheckStatus (status);
1058 public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
1060 if (pen == null)
1061 throw new ArgumentNullException ("pen");
1062 DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1065 public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
1067 if (pen == null)
1068 throw new ArgumentNullException ("pen");
1069 DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1072 public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
1074 if (pen == null)
1075 throw new ArgumentNullException ("pen");
1076 Status status = GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1077 GDIPlus.CheckStatus (status);
1080 // Microsoft documentation states that the signature for this member should be
1081 // public void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle
1082 // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
1083 public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
1085 if (pen == null)
1086 throw new ArgumentNullException ("pen");
1087 Status status = GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1088 GDIPlus.CheckStatus (status);
1091 public void DrawPolygon (Pen pen, Point [] points)
1093 if (pen == null)
1094 throw new ArgumentNullException ("pen");
1095 if (points == null)
1096 throw new ArgumentNullException ("points");
1097 Status status = GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
1098 GDIPlus.CheckStatus (status);
1101 public void DrawPolygon (Pen pen, PointF [] points)
1103 if (pen == null)
1104 throw new ArgumentNullException ("pen");
1105 if (points == null)
1106 throw new ArgumentNullException ("points");
1107 Status status = GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
1108 GDIPlus.CheckStatus (status);
1111 public void DrawRectangle (Pen pen, Rectangle rect)
1113 if (pen == null)
1114 throw new ArgumentNullException ("pen");
1115 DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
1118 public void DrawRectangle (Pen pen, float x, float y, float width, float height)
1120 if (pen == null)
1121 throw new ArgumentNullException ("pen");
1122 Status status = GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
1123 GDIPlus.CheckStatus (status);
1126 public void DrawRectangle (Pen pen, int x, int y, int width, int height)
1128 if (pen == null)
1129 throw new ArgumentNullException ("pen");
1130 Status status = GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
1131 GDIPlus.CheckStatus (status);
1134 public void DrawRectangles (Pen pen, RectangleF [] rects)
1136 if (pen == null)
1137 throw new ArgumentNullException ("image");
1138 if (rects == null)
1139 throw new ArgumentNullException ("rects");
1140 Status status = GDIPlus.GdipDrawRectangles (nativeObject, pen.nativeObject, rects, rects.Length);
1141 GDIPlus.CheckStatus (status);
1144 public void DrawRectangles (Pen pen, Rectangle [] rects)
1146 if (pen == null)
1147 throw new ArgumentNullException ("image");
1148 if (rects == null)
1149 throw new ArgumentNullException ("rects");
1150 Status status = GDIPlus.GdipDrawRectanglesI (nativeObject, pen.nativeObject, rects, rects.Length);
1151 GDIPlus.CheckStatus (status);
1154 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle)
1156 DrawString (s, font, brush, layoutRectangle, null);
1159 public void DrawString (string s, Font font, Brush brush, PointF point)
1161 DrawString (s, font, brush, new RectangleF (point.X, point.Y, 0, 0), null);
1164 public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format)
1166 DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
1169 public void DrawString (string s, Font font, Brush brush, float x, float y)
1171 DrawString (s, font, brush, new RectangleF (x, y, 0, 0), null);
1174 public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format)
1176 DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
1179 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
1181 if (font == null)
1182 throw new ArgumentNullException ("font");
1183 if (brush == null)
1184 throw new ArgumentNullException ("brush");
1185 if (s == null || s.Length == 0)
1186 return;
1188 Status status = GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, format != null ? format.NativeObject : IntPtr.Zero, brush.nativeObject);
1189 GDIPlus.CheckStatus (status);
1192 public void EndContainer (GraphicsContainer container)
1194 #if NET_2_0
1195 if (container == null)
1196 throw new ArgumentNullException ("container");
1197 #endif
1198 Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
1199 GDIPlus.CheckStatus (status);
1202 private const string MetafileEnumeration = "Metafiles enumeration, for both WMF and EMF formats, isn't supported.";
1204 [MonoTODO (MetafileEnumeration)]
1205 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
1207 throw new NotImplementedException ();
1210 [MonoTODO (MetafileEnumeration)]
1211 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
1213 throw new NotImplementedException ();
1216 [MonoTODO (MetafileEnumeration)]
1217 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
1219 throw new NotImplementedException ();
1222 [MonoTODO (MetafileEnumeration)]
1223 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
1225 throw new NotImplementedException ();
1228 [MonoTODO (MetafileEnumeration)]
1229 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
1231 throw new NotImplementedException ();
1234 [MonoTODO (MetafileEnumeration)]
1235 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
1237 throw new NotImplementedException ();
1240 [MonoTODO (MetafileEnumeration)]
1241 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1243 throw new NotImplementedException ();
1246 [MonoTODO (MetafileEnumeration)]
1247 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1249 throw new NotImplementedException ();
1252 [MonoTODO (MetafileEnumeration)]
1253 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1255 throw new NotImplementedException ();
1258 [MonoTODO (MetafileEnumeration)]
1259 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1261 throw new NotImplementedException ();
1264 [MonoTODO (MetafileEnumeration)]
1265 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1267 throw new NotImplementedException ();
1270 [MonoTODO (MetafileEnumeration)]
1271 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1273 throw new NotImplementedException ();
1276 [MonoTODO (MetafileEnumeration)]
1277 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1279 throw new NotImplementedException ();
1282 [MonoTODO (MetafileEnumeration)]
1283 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1285 throw new NotImplementedException ();
1288 [MonoTODO (MetafileEnumeration)]
1289 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1291 throw new NotImplementedException ();
1294 [MonoTODO (MetafileEnumeration)]
1295 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1297 throw new NotImplementedException ();
1300 [MonoTODO (MetafileEnumeration)]
1301 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1303 throw new NotImplementedException ();
1306 [MonoTODO (MetafileEnumeration)]
1307 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1309 throw new NotImplementedException ();
1312 [MonoTODO (MetafileEnumeration)]
1313 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1315 throw new NotImplementedException ();
1318 [MonoTODO (MetafileEnumeration)]
1319 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1321 throw new NotImplementedException ();
1324 [MonoTODO (MetafileEnumeration)]
1325 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1327 throw new NotImplementedException ();
1330 [MonoTODO (MetafileEnumeration)]
1331 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1333 throw new NotImplementedException ();
1336 [MonoTODO (MetafileEnumeration)]
1337 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1339 throw new NotImplementedException ();
1342 [MonoTODO (MetafileEnumeration)]
1343 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1345 throw new NotImplementedException ();
1348 [MonoTODO (MetafileEnumeration)]
1349 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1351 throw new NotImplementedException ();
1354 [MonoTODO (MetafileEnumeration)]
1355 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1357 throw new NotImplementedException ();
1360 [MonoTODO (MetafileEnumeration)]
1361 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1363 throw new NotImplementedException ();
1366 [MonoTODO (MetafileEnumeration)]
1367 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1369 throw new NotImplementedException ();
1372 [MonoTODO (MetafileEnumeration)]
1373 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1375 throw new NotImplementedException ();
1378 [MonoTODO (MetafileEnumeration)]
1379 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1381 throw new NotImplementedException ();
1384 [MonoTODO (MetafileEnumeration)]
1385 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1387 throw new NotImplementedException ();
1390 [MonoTODO (MetafileEnumeration)]
1391 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1393 throw new NotImplementedException ();
1396 [MonoTODO (MetafileEnumeration)]
1397 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1399 throw new NotImplementedException ();
1402 [MonoTODO (MetafileEnumeration)]
1403 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1405 throw new NotImplementedException ();
1408 [MonoTODO (MetafileEnumeration)]
1409 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1411 throw new NotImplementedException ();
1414 [MonoTODO (MetafileEnumeration)]
1415 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1417 throw new NotImplementedException ();
1420 public void ExcludeClip (Rectangle rect)
1422 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);
1423 GDIPlus.CheckStatus (status);
1426 public void ExcludeClip (Region region)
1428 if (region == null)
1429 throw new ArgumentNullException ("region");
1430 Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Exclude);
1431 GDIPlus.CheckStatus (status);
1435 public void FillClosedCurve (Brush brush, PointF [] points)
1437 if (brush == null)
1438 throw new ArgumentNullException ("brush");
1439 if (points == null)
1440 throw new ArgumentNullException ("points");
1441 Status status = GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
1442 GDIPlus.CheckStatus (status);
1445 public void FillClosedCurve (Brush brush, Point [] points)
1447 if (brush == null)
1448 throw new ArgumentNullException ("brush");
1449 if (points == null)
1450 throw new ArgumentNullException ("points");
1451 Status status = GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
1452 GDIPlus.CheckStatus (status);
1456 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode)
1458 if (brush == null)
1459 throw new ArgumentNullException ("brush");
1460 if (points == null)
1461 throw new ArgumentNullException ("points");
1462 FillClosedCurve (brush, points, fillmode, 0.5f);
1465 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode)
1467 if (brush == null)
1468 throw new ArgumentNullException ("brush");
1469 if (points == null)
1470 throw new ArgumentNullException ("points");
1471 FillClosedCurve (brush, points, fillmode, 0.5f);
1474 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension)
1476 if (brush == null)
1477 throw new ArgumentNullException ("brush");
1478 if (points == null)
1479 throw new ArgumentNullException ("points");
1480 Status status = GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1481 GDIPlus.CheckStatus (status);
1484 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension)
1486 if (brush == null)
1487 throw new ArgumentNullException ("brush");
1488 if (points == null)
1489 throw new ArgumentNullException ("points");
1490 Status status = GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1491 GDIPlus.CheckStatus (status);
1494 public void FillEllipse (Brush brush, Rectangle rect)
1496 if (brush == null)
1497 throw new ArgumentNullException ("brush");
1498 FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1501 public void FillEllipse (Brush brush, RectangleF rect)
1503 if (brush == null)
1504 throw new ArgumentNullException ("brush");
1505 FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1508 public void FillEllipse (Brush brush, float x, float y, float width, float height)
1510 if (brush == null)
1511 throw new ArgumentNullException ("brush");
1512 Status status = GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
1513 GDIPlus.CheckStatus (status);
1516 public void FillEllipse (Brush brush, int x, int y, int width, int height)
1518 if (brush == null)
1519 throw new ArgumentNullException ("brush");
1520 Status status = GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
1521 GDIPlus.CheckStatus (status);
1524 public void FillPath (Brush brush, GraphicsPath path)
1526 if (brush == null)
1527 throw new ArgumentNullException ("brush");
1528 if (path == null)
1529 throw new ArgumentNullException ("path");
1530 Status status = GDIPlus.GdipFillPath (nativeObject, brush.NativeObject, path.NativeObject);
1531 GDIPlus.CheckStatus (status);
1534 public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)
1536 if (brush == null)
1537 throw new ArgumentNullException ("brush");
1538 Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1539 GDIPlus.CheckStatus (status);
1542 public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
1544 if (brush == null)
1545 throw new ArgumentNullException ("brush");
1546 Status status = GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1547 GDIPlus.CheckStatus (status);
1550 public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
1552 if (brush == null)
1553 throw new ArgumentNullException ("brush");
1554 Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1555 GDIPlus.CheckStatus (status);
1558 public void FillPolygon (Brush brush, PointF [] points)
1560 if (brush == null)
1561 throw new ArgumentNullException ("brush");
1562 if (points == null)
1563 throw new ArgumentNullException ("points");
1564 Status status = GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
1565 GDIPlus.CheckStatus (status);
1568 public void FillPolygon (Brush brush, Point [] points)
1570 if (brush == null)
1571 throw new ArgumentNullException ("brush");
1572 if (points == null)
1573 throw new ArgumentNullException ("points");
1574 Status status = GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
1575 GDIPlus.CheckStatus (status);
1578 public void FillPolygon (Brush brush, Point [] points, FillMode fillMode)
1580 if (brush == null)
1581 throw new ArgumentNullException ("brush");
1582 if (points == null)
1583 throw new ArgumentNullException ("points");
1584 Status status = GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1585 GDIPlus.CheckStatus (status);
1588 public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode)
1590 if (brush == null)
1591 throw new ArgumentNullException ("brush");
1592 if (points == null)
1593 throw new ArgumentNullException ("points");
1594 Status status = GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1595 GDIPlus.CheckStatus (status);
1598 public void FillRectangle (Brush brush, RectangleF rect)
1600 if (brush == null)
1601 throw new ArgumentNullException ("brush");
1602 FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1605 public void FillRectangle (Brush brush, Rectangle rect)
1607 if (brush == null)
1608 throw new ArgumentNullException ("brush");
1609 FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1612 public void FillRectangle (Brush brush, int x, int y, int width, int height)
1614 if (brush == null)
1615 throw new ArgumentNullException ("brush");
1617 Status status = GDIPlus.GdipFillRectangleI (nativeObject, brush.nativeObject, x, y, width, height);
1618 GDIPlus.CheckStatus (status);
1621 public void FillRectangle (Brush brush, float x, float y, float width, float height)
1623 if (brush == null)
1624 throw new ArgumentNullException ("brush");
1626 Status status = GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
1627 GDIPlus.CheckStatus (status);
1630 public void FillRectangles (Brush brush, Rectangle [] rects)
1632 if (brush == null)
1633 throw new ArgumentNullException ("brush");
1634 if (rects == null)
1635 throw new ArgumentNullException ("rects");
1637 Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
1638 GDIPlus.CheckStatus (status);
1641 public void FillRectangles (Brush brush, RectangleF [] rects)
1643 if (brush == null)
1644 throw new ArgumentNullException ("brush");
1645 if (rects == null)
1646 throw new ArgumentNullException ("rects");
1648 Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
1649 GDIPlus.CheckStatus (status);
1653 public void FillRegion (Brush brush, Region region)
1655 if (brush == null)
1656 throw new ArgumentNullException ("brush");
1657 if (region == null)
1658 throw new ArgumentNullException ("region");
1660 Status status = GDIPlus.GdipFillRegion (nativeObject, brush.NativeObject, region.NativeObject);
1661 GDIPlus.CheckStatus(status);
1665 public void Flush ()
1667 Flush (FlushIntention.Flush);
1671 public void Flush (FlushIntention intention)
1673 if (nativeObject == IntPtr.Zero) {
1674 return;
1677 Status status = GDIPlus.GdipFlush (nativeObject, intention);
1678 GDIPlus.CheckStatus (status);
1679 if (GDIPlus.UseCarbonDrawable && context.ctx != IntPtr.Zero)
1680 Carbon.CGContextSynchronize (context.ctx);
1683 [EditorBrowsable (EditorBrowsableState.Advanced)]
1684 public static Graphics FromHdc (IntPtr hdc)
1686 IntPtr graphics;
1687 Status status = GDIPlus.GdipCreateFromHDC (hdc, out graphics);
1688 GDIPlus.CheckStatus (status);
1689 return new Graphics (graphics);
1692 [MonoTODO]
1693 [EditorBrowsable (EditorBrowsableState.Advanced)]
1694 public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
1696 throw new NotImplementedException ();
1699 [EditorBrowsable (EditorBrowsableState.Advanced)]
1700 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1701 public static Graphics FromHdcInternal (IntPtr hdc)
1703 GDIPlus.Display = hdc;
1704 return null;
1707 [EditorBrowsable (EditorBrowsableState.Advanced)]
1708 public static Graphics FromHwnd (IntPtr hwnd)
1710 IntPtr graphics;
1712 if (GDIPlus.UseCarbonDrawable) {
1713 CarbonContext context = Carbon.GetCGContextForView (hwnd);
1714 GDIPlus.GdipCreateFromContext_macosx (context.ctx, context.width, context.height, out graphics);
1716 Graphics g = new Graphics (graphics);
1717 g.context = context;
1719 return g;
1721 if (GDIPlus.UseX11Drawable) {
1722 if (GDIPlus.Display == IntPtr.Zero) {
1723 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
1724 if (GDIPlus.Display == IntPtr.Zero)
1725 throw new NotSupportedException ("Could not open display (X-Server required. Check you DISPLAY environment variable)");
1727 if (hwnd == IntPtr.Zero) {
1728 hwnd = GDIPlus.XRootWindow (GDIPlus.Display, GDIPlus.XDefaultScreen (GDIPlus.Display));
1731 return FromXDrawable (hwnd, GDIPlus.Display);
1735 Status status = GDIPlus.GdipCreateFromHWND (hwnd, out graphics);
1736 GDIPlus.CheckStatus (status);
1738 return new Graphics (graphics);
1741 [EditorBrowsable (EditorBrowsableState.Advanced)]
1742 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1743 public static Graphics FromHwndInternal (IntPtr hwnd)
1745 return FromHwnd (hwnd);
1748 public static Graphics FromImage (Image image)
1750 IntPtr graphics;
1752 if (image == null)
1753 throw new ArgumentNullException ("image");
1755 if ((image.PixelFormat & PixelFormat.Indexed) != 0)
1756 throw new Exception (Locale.GetText ("Cannot create Graphics from an indexed bitmap."));
1758 Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
1759 GDIPlus.CheckStatus (status);
1760 Graphics result = new Graphics (graphics);
1762 if (GDIPlus.RunningOnUnix ()) {
1763 Rectangle rect = new Rectangle (0,0, image.Width, image.Height);
1764 GDIPlus.GdipSetVisibleClip_linux (result.NativeObject, ref rect);
1767 return result;
1770 internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
1772 IntPtr graphics;
1774 Status s = GDIPlus.GdipCreateFromXDrawable_linux (drawable, display, out graphics);
1775 GDIPlus.CheckStatus (s);
1776 return new Graphics (graphics);
1779 [MonoTODO]
1780 public static IntPtr GetHalftonePalette ()
1782 throw new NotImplementedException ();
1785 #if !NET_2_0
1786 [EditorBrowsable (EditorBrowsableState.Advanced)]
1787 #endif
1788 public IntPtr GetHdc ()
1790 GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out deviceContextHdc));
1791 return deviceContextHdc;
1794 public Color GetNearestColor (Color color)
1796 int argb;
1798 Status status = GDIPlus.GdipGetNearestColor (nativeObject, out argb);
1799 GDIPlus.CheckStatus (status);
1801 return Color.FromArgb (argb);
1805 public void IntersectClip (Region region)
1807 if (region == null)
1808 throw new ArgumentNullException ("region");
1809 Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Intersect);
1810 GDIPlus.CheckStatus (status);
1813 public void IntersectClip (RectangleF rect)
1815 Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1816 GDIPlus.CheckStatus (status);
1819 public void IntersectClip (Rectangle rect)
1821 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1822 GDIPlus.CheckStatus (status);
1825 public bool IsVisible (Point point)
1827 bool isVisible = false;
1829 Status status = GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
1830 GDIPlus.CheckStatus (status);
1832 return isVisible;
1836 public bool IsVisible (RectangleF rect)
1838 bool isVisible = false;
1840 Status status = GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1841 GDIPlus.CheckStatus (status);
1843 return isVisible;
1846 public bool IsVisible (PointF point)
1848 bool isVisible = false;
1850 Status status = GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
1851 GDIPlus.CheckStatus (status);
1853 return isVisible;
1856 public bool IsVisible (Rectangle rect)
1858 bool isVisible = false;
1860 Status status = GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1861 GDIPlus.CheckStatus (status);
1863 return isVisible;
1866 public bool IsVisible (float x, float y)
1868 return IsVisible (new PointF (x, y));
1871 public bool IsVisible (int x, int y)
1873 return IsVisible (new Point (x, y));
1876 public bool IsVisible (float x, float y, float width, float height)
1878 return IsVisible (new RectangleF (x, y, width, height));
1882 public bool IsVisible (int x, int y, int width, int height)
1884 return IsVisible (new Rectangle (x, y, width, height));
1888 public Region[] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
1890 if ((text == null) || (text.Length == 0))
1891 return new Region [0];
1893 if (font == null)
1894 throw new ArgumentNullException ("font");
1896 if (stringFormat == null)
1897 throw new ArgumentException ("stringFormat");
1899 int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
1900 if (regcount == 0)
1901 return new Region[0];
1903 IntPtr[] native_regions = new IntPtr [regcount];
1904 Region[] regions = new Region [regcount];
1906 for (int i = 0; i < regcount; i++) {
1907 regions[i] = new Region ();
1908 native_regions[i] = regions[i].NativeObject;
1911 Status status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
1912 font.NativeObject, ref layoutRect, stringFormat.NativeObject, regcount, out native_regions[0]);
1913 GDIPlus.CheckStatus (status);
1915 return regions;
1918 private unsafe SizeF GdipMeasureString (IntPtr graphics, string text, Font font, ref RectangleF layoutRect,
1919 IntPtr stringFormat)
1921 if ((text == null) || (text.Length == 0))
1922 return SizeF.Empty;
1924 if (font == null)
1925 throw new ArgumentNullException ("font");
1927 RectangleF boundingBox = new RectangleF ();
1929 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject,
1930 ref layoutRect, stringFormat, out boundingBox, null, null);
1931 GDIPlus.CheckStatus (status);
1933 return new SizeF (boundingBox.Width, boundingBox.Height);
1936 public SizeF MeasureString (string text, Font font)
1938 return MeasureString (text, font, SizeF.Empty);
1941 public SizeF MeasureString (string text, Font font, SizeF layoutArea)
1943 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1944 return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1947 public SizeF MeasureString (string text, Font font, int width)
1949 RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1950 return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1953 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat)
1955 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1956 IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1957 return GdipMeasureString (nativeObject, text, font, ref rect, format);
1960 public SizeF MeasureString (string text, Font font, int width, StringFormat format)
1962 RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1963 IntPtr stringFormat = (format == null) ? IntPtr.Zero : format.NativeObject;
1964 return GdipMeasureString (nativeObject, text, font, ref rect, stringFormat);
1967 public SizeF MeasureString (string text, Font font, PointF origin, StringFormat stringFormat)
1969 RectangleF rect = new RectangleF (origin.X, origin.Y, 0, 0);
1970 IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1971 return GdipMeasureString (nativeObject, text, font, ref rect, format);
1974 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat,
1975 out int charactersFitted, out int linesFilled)
1977 charactersFitted = 0;
1978 linesFilled = 0;
1980 if ((text == null) || (text.Length == 0))
1981 return SizeF.Empty;
1983 if (font == null)
1984 throw new ArgumentNullException ("font");
1986 RectangleF boundingBox = new RectangleF ();
1987 RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1989 IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1991 unsafe {
1992 fixed (int* pc = &charactersFitted, pl = &linesFilled) {
1993 Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length,
1994 font.NativeObject, ref rect, format, out boundingBox, pc, pl);
1995 GDIPlus.CheckStatus (status);
1998 return new SizeF (boundingBox.Width, boundingBox.Height);
2001 public void MultiplyTransform (Matrix matrix)
2003 MultiplyTransform (matrix, MatrixOrder.Prepend);
2006 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
2008 if (matrix == null)
2009 throw new ArgumentNullException ("matrix");
2011 Status status = GDIPlus.GdipMultiplyWorldTransform (nativeObject, matrix.nativeMatrix, order);
2012 GDIPlus.CheckStatus (status);
2015 [EditorBrowsable (EditorBrowsableState.Advanced)]
2016 [SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
2017 public void ReleaseHdc (IntPtr hdc)
2019 ReleaseHdcInternal (hdc);
2022 #if NET_2_0
2023 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2024 public void ReleaseHdc ()
2026 ReleaseHdcInternal (deviceContextHdc);
2028 #endif
2030 [MonoLimitation ("Can only be used when hdc was provided by Graphics.GetHdc() method")]
2031 #if NET_2_0
2032 [EditorBrowsable (EditorBrowsableState.Never)]
2033 #else
2034 [EditorBrowsable (EditorBrowsableState.Advanced)]
2035 #endif
2036 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2037 public void ReleaseHdcInternal (IntPtr hdc)
2039 Status status = Status.InvalidParameter;
2040 if (hdc == deviceContextHdc) {
2041 status = GDIPlus.GdipReleaseDC (nativeObject, deviceContextHdc);
2042 deviceContextHdc = IntPtr.Zero;
2044 GDIPlus.CheckStatus (status);
2047 public void ResetClip ()
2049 Status status = GDIPlus.GdipResetClip (nativeObject);
2050 GDIPlus.CheckStatus (status);
2053 public void ResetTransform ()
2055 Status status = GDIPlus.GdipResetWorldTransform (nativeObject);
2056 GDIPlus.CheckStatus (status);
2059 public void Restore (GraphicsState gstate)
2061 // the possible NRE thrown by gstate.nativeState match MS behaviour
2062 Status status = GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
2063 GDIPlus.CheckStatus (status);
2066 public void RotateTransform (float angle)
2068 RotateTransform (angle, MatrixOrder.Prepend);
2071 public void RotateTransform (float angle, MatrixOrder order)
2073 Status status = GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
2074 GDIPlus.CheckStatus (status);
2077 public GraphicsState Save ()
2079 uint saveState;
2080 Status status = GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
2081 GDIPlus.CheckStatus (status);
2083 GraphicsState state = new GraphicsState ();
2084 state.nativeState = saveState;
2085 return state;
2088 public void ScaleTransform (float sx, float sy)
2090 ScaleTransform (sx, sy, MatrixOrder.Prepend);
2093 public void ScaleTransform (float sx, float sy, MatrixOrder order)
2095 Status status = GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
2096 GDIPlus.CheckStatus (status);
2100 public void SetClip (RectangleF rect)
2102 SetClip (rect, CombineMode.Replace);
2106 public void SetClip (GraphicsPath path)
2108 SetClip (path, CombineMode.Replace);
2112 public void SetClip (Rectangle rect)
2114 SetClip (rect, CombineMode.Replace);
2118 public void SetClip (Graphics g)
2120 SetClip (g, CombineMode.Replace);
2124 public void SetClip (Graphics g, CombineMode combineMode)
2126 if (g == null)
2127 throw new ArgumentNullException ("g");
2129 Status status = GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
2130 GDIPlus.CheckStatus (status);
2134 public void SetClip (Rectangle rect, CombineMode combineMode)
2136 Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2137 GDIPlus.CheckStatus (status);
2141 public void SetClip (RectangleF rect, CombineMode combineMode)
2143 Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2144 GDIPlus.CheckStatus (status);
2148 public void SetClip (Region region, CombineMode combineMode)
2150 if (region == null)
2151 throw new ArgumentNullException ("region");
2152 Status status = GDIPlus.GdipSetClipRegion(nativeObject, region.NativeObject, combineMode);
2153 GDIPlus.CheckStatus (status);
2157 public void SetClip (GraphicsPath path, CombineMode combineMode)
2159 if (path == null)
2160 throw new ArgumentNullException ("path");
2161 Status status = GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
2162 GDIPlus.CheckStatus (status);
2166 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts)
2168 if (pts == null)
2169 throw new ArgumentNullException ("pts");
2171 IntPtr ptrPt = GDIPlus.FromPointToUnManagedMemory (pts);
2173 Status status = GDIPlus.GdipTransformPoints (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2174 GDIPlus.CheckStatus (status);
2176 GDIPlus.FromUnManagedMemoryToPoint (ptrPt, pts);
2180 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
2182 if (pts == null)
2183 throw new ArgumentNullException ("pts");
2184 IntPtr ptrPt = GDIPlus.FromPointToUnManagedMemoryI (pts);
2186 Status status = GDIPlus.GdipTransformPointsI (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2187 GDIPlus.CheckStatus (status);
2189 GDIPlus.FromUnManagedMemoryToPointI (ptrPt, pts);
2193 public void TranslateClip (int dx, int dy)
2195 Status status = GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);
2196 GDIPlus.CheckStatus (status);
2200 public void TranslateClip (float dx, float dy)
2202 Status status = GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
2203 GDIPlus.CheckStatus (status);
2206 public void TranslateTransform (float dx, float dy)
2208 TranslateTransform (dx, dy, MatrixOrder.Prepend);
2212 public void TranslateTransform (float dx, float dy, MatrixOrder order)
2214 Status status = GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
2215 GDIPlus.CheckStatus (status);
2218 public Region Clip {
2219 get {
2220 Region reg = new Region();
2221 Status status = GDIPlus.GdipGetClip (nativeObject, reg.NativeObject);
2222 GDIPlus.CheckStatus (status);
2223 return reg;
2225 set {
2226 SetClip (value, CombineMode.Replace);
2230 public RectangleF ClipBounds {
2231 get {
2232 RectangleF rect = new RectangleF ();
2233 Status status = GDIPlus.GdipGetClipBounds (nativeObject, out rect);
2234 GDIPlus.CheckStatus (status);
2235 return rect;
2239 public CompositingMode CompositingMode {
2240 get {
2241 CompositingMode mode;
2242 Status status = GDIPlus.GdipGetCompositingMode (nativeObject, out mode);
2243 GDIPlus.CheckStatus (status);
2245 return mode;
2247 set {
2248 Status status = GDIPlus.GdipSetCompositingMode (nativeObject, value);
2249 GDIPlus.CheckStatus (status);
2254 public CompositingQuality CompositingQuality {
2255 get {
2256 CompositingQuality quality;
2258 Status status = GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
2259 GDIPlus.CheckStatus (status);
2260 return quality;
2262 set {
2263 Status status = GDIPlus.GdipSetCompositingQuality (nativeObject, value);
2264 GDIPlus.CheckStatus (status);
2268 public float DpiX {
2269 get {
2270 float x;
2272 Status status = GDIPlus.GdipGetDpiX (nativeObject, out x);
2273 GDIPlus.CheckStatus (status);
2274 return x;
2278 public float DpiY {
2279 get {
2280 float y;
2282 Status status = GDIPlus.GdipGetDpiY (nativeObject, out y);
2283 GDIPlus.CheckStatus (status);
2284 return y;
2288 public InterpolationMode InterpolationMode {
2289 get {
2290 InterpolationMode imode = InterpolationMode.Invalid;
2291 Status status = GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
2292 GDIPlus.CheckStatus (status);
2293 return imode;
2295 set {
2296 Status status = GDIPlus.GdipSetInterpolationMode (nativeObject, value);
2297 GDIPlus.CheckStatus (status);
2301 public bool IsClipEmpty {
2302 get {
2303 bool isEmpty = false;
2305 Status status = GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
2306 GDIPlus.CheckStatus (status);
2307 return isEmpty;
2311 public bool IsVisibleClipEmpty {
2312 get {
2313 bool isEmpty = false;
2315 Status status = GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
2316 GDIPlus.CheckStatus (status);
2317 return isEmpty;
2321 public float PageScale {
2322 get {
2323 float scale;
2325 Status status = GDIPlus.GdipGetPageScale (nativeObject, out scale);
2326 GDIPlus.CheckStatus (status);
2327 return scale;
2329 set {
2330 Status status = GDIPlus.GdipSetPageScale (nativeObject, value);
2331 GDIPlus.CheckStatus (status);
2335 public GraphicsUnit PageUnit {
2336 get {
2337 GraphicsUnit unit;
2339 Status status = GDIPlus.GdipGetPageUnit (nativeObject, out unit);
2340 GDIPlus.CheckStatus (status);
2341 return unit;
2343 set {
2344 Status status = GDIPlus.GdipSetPageUnit (nativeObject, value);
2345 GDIPlus.CheckStatus (status);
2349 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2350 public PixelOffsetMode PixelOffsetMode {
2351 get {
2352 PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
2354 Status status = GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
2355 GDIPlus.CheckStatus (status);
2356 return pixelOffset;
2358 set {
2359 Status status = GDIPlus.GdipSetPixelOffsetMode (nativeObject, value);
2360 GDIPlus.CheckStatus (status);
2364 public Point RenderingOrigin {
2365 get {
2366 int x, y;
2367 Status status = GDIPlus.GdipGetRenderingOrigin (nativeObject, out x, out y);
2368 GDIPlus.CheckStatus (status);
2369 return new Point (x, y);
2372 set {
2373 Status status = GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
2374 GDIPlus.CheckStatus (status);
2378 public SmoothingMode SmoothingMode {
2379 get {
2380 SmoothingMode mode = SmoothingMode.Invalid;
2382 Status status = GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
2383 GDIPlus.CheckStatus (status);
2384 return mode;
2387 set {
2388 Status status = GDIPlus.GdipSetSmoothingMode (nativeObject, value);
2389 GDIPlus.CheckStatus (status);
2393 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2394 public int TextContrast {
2395 get {
2396 int contrast;
2398 Status status = GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
2399 GDIPlus.CheckStatus (status);
2400 return contrast;
2403 set {
2404 Status status = GDIPlus.GdipSetTextContrast (nativeObject, value);
2405 GDIPlus.CheckStatus (status);
2409 public TextRenderingHint TextRenderingHint {
2410 get {
2411 TextRenderingHint hint;
2413 Status status = GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
2414 GDIPlus.CheckStatus (status);
2415 return hint;
2418 set {
2419 Status status = GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
2420 GDIPlus.CheckStatus (status);
2424 public Matrix Transform {
2425 get {
2426 Matrix matrix = new Matrix ();
2427 Status status = GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
2428 GDIPlus.CheckStatus (status);
2429 return matrix;
2431 set {
2432 if (value == null)
2433 throw new ArgumentNullException ("value");
2435 Status status = GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
2436 GDIPlus.CheckStatus (status);
2440 public RectangleF VisibleClipBounds {
2441 get {
2442 RectangleF rect;
2444 Status status = GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
2445 GDIPlus.CheckStatus (status);
2446 return rect;
2450 #if NET_2_0
2451 [MonoTODO]
2452 [EditorBrowsable (EditorBrowsableState.Never)]
2453 public object GetContextInfo ()
2455 // only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
2456 throw new NotImplementedException ();
2458 #endif