2 // Sample application for drawing figures using TextureBrush
3 // with different WrapModes
6 // Ravindra (rkumar@novell.com)
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Drawing
.Drawing2D
;
34 using System
.Drawing
.Imaging
;
36 namespace MonoSamples
.System
.Drawing
38 public class TextureWrapModes
40 Image img
; // To be used by brush
41 Graphics gr
; // To be used for creating a new bitmap
49 public TextureWrapModes (string imgName
, int wd
, int ht
, int top
, int sp
)
53 bmp
= new Bitmap (wd
,ht
);
54 gr
= Graphics
.FromImage (bmp
);
55 img
= Image
.FromFile ("./bitmaps/" + imgName
);
58 public void DrawWrapModes ()
62 TextureBrush tbr
= new TextureBrush (img
);
65 tbr
.WrapMode
= WrapMode
.Clamp
;
66 gr
.FillRectangle (tbr
, 0, 0, width
, height
);
67 top
= top
+ height
+ spacing
;
69 tbr
= new TextureBrush (img
);
72 gr
.FillRectangle (tbr
, left
, top
, width
, height
);
73 top
= top
+ height
+ spacing
;
76 tbr
.WrapMode
= WrapMode
.Tile
;
77 gr
.FillRectangle (tbr
, left
, top
, width
, height
);
78 top
= top
+ height
+ spacing
;
81 tbr
.WrapMode
= WrapMode
.TileFlipX
;
82 gr
.FillRectangle (tbr
, left
, top
, width
, height
);
83 top
= top
+ height
+ spacing
;
86 tbr
.WrapMode
= WrapMode
.TileFlipY
;
87 gr
.FillRectangle (tbr
, left
, top
, width
, height
);
88 top
= top
+ height
+ spacing
;
91 tbr
.WrapMode
= WrapMode
.TileFlipXY
;
92 gr
.FillRectangle (tbr
, left
, top
, width
, height
);
93 top
= top
+ height
+ spacing
;
98 public void SaveDrawing ()
101 bmp
.Save ("TextureWrapModes.png", ImageFormat
.Png
);
104 // Main to draw the things
105 public static void Main ()
107 // Make sure that the image dimensions are
108 // sufficient to hold all the test results.
109 // TextureWrapModes (imgName, width, height, top, spacing)
111 TextureWrapModes twm
= new TextureWrapModes ("horse.png", 650,
114 // Draw different wrapmodes
115 twm
.DrawWrapModes ();
117 // Save the drawing when done