示例#1
0
		public static void Draw(Graphics graphics)
		{
			var generator = graphics.Generator;
			var image = TestIcons.TestImage(generator);
			// lines
			var whitePen = Pens.White(generator);
			graphics.DrawLine(whitePen, 1, 1, 99, 99);
			graphics.DrawLine(whitePen, 50, 1, 50, 99);
			graphics.DrawLine(whitePen, 1, 51, 99, 51);

			graphics.DrawRectangle(Pens.White(generator), 101, 1, 100, 100);
			graphics.DrawRectangle(Pens.White(generator), 101, 1, 10, 10);

			graphics.DrawEllipse(Pens.Green(generator), 101, 1, 100, 100);

			graphics.DrawPolygon(Pens.White(generator), new PointF(203, 1), new PointF(253, 51), new Point(203, 101), new PointF(203, 1), new PointF(253, 1), new PointF(253, 101), new PointF(203, 101));

			var rect = new RectangleF(255, 1, 100, 100);
			graphics.DrawArc(Pens.LightGreen(generator), rect, 180, 90);
			graphics.DrawArc(Pens.SkyBlue(generator), rect, 0, 90);
			rect.Inflate(-15, 0);
			graphics.DrawArc(Pens.FloralWhite(generator), rect, -45, 90);
			rect.Inflate(-5, -20);
			graphics.DrawArc(Pens.SlateGray(generator), rect, -45, 270);
			rect.Inflate(-10, -10);
			graphics.DrawArc(Pens.SteelBlue(generator), rect, 180 + 45, 270);

			graphics.DrawImage(image, 100, 1, 100, 100);

			graphics.DrawText(Fonts.Sans(12 * graphics.PointsPerPixel, generator: generator), Colors.White, 0, 104, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

			// filled
			graphics.FillRectangle(Brushes.White(generator), 101, 120, 100, 100);
			graphics.FillRectangle(Brushes.Gray(generator), 101, 120, 10, 10);

			graphics.FillEllipse(Brushes.Green(generator), 101, 120, 100, 100);

			graphics.FillPolygon(Brushes.White(generator), new PointF(202, 120), new PointF(252, 170), new Point(202, 220), new PointF(202, 120));

			rect = new RectangleF(255, 120, 100, 100);
			graphics.FillPie(Brushes.LightGreen(generator), rect, 180, 90);
			graphics.FillPie(Brushes.SkyBlue(generator), rect, 0, 90);
			rect.Inflate(-15, 0);
			graphics.FillPie(Brushes.FloralWhite(generator), rect, -45, 90);
			rect.Inflate(-5, -20);
			graphics.FillPie(Brushes.SlateGray(generator), rect, -45, 270);
			rect.Inflate(-10, -10);
			graphics.FillPie(Brushes.SteelBlue(generator), rect, 180 + 45, 270);


			graphics.DrawImage(image, 101, 120, 100, 100);
		}
示例#2
0
 public void CoptyToEto(ed.Graphics graphics)
 {
     using (var eto = LockEtoBitmap())
         graphics.DrawImage(eto, 0, 0);
 }
示例#3
0
		Control DrawImageToRect()
		{
			var image64 = new Bitmap(new Size(64, 64), PixelFormat.Format32bppRgba);
			var image32 = new Bitmap(new Size(32, 32), PixelFormat.Format32bppRgba);

			using (var g = new Graphics(image64))
				g.Clear(Brushes.Cached(Colors.Green) as SolidBrush);

			using (var g = new Graphics(image32))
				g.Clear(Brushes.Cached(Colors.Blue) as SolidBrush);

			var bitmap = new Bitmap(new Size(105, 105), PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				// draw the big image at the origin, but with a smaller dest rect
				g.DrawImage(image64, new RectangleF(0, 0, 32, 32), new RectangleF(0, 0, 32, 32));
				// draw two guide images to indicate how big the green image should be
				g.DrawImage(image32, new PointF(70, 0));
				g.DrawImage(image32, new PointF(0, 70));
			}
			return new DrawableImageView { Image = bitmap };
		}
示例#4
0
		Control CloneTiles()
		{
			// Creates a duplicate of the bitmap by cloning tiles of it
			// and drawing them in the same location in the duplicate.
			var image = TestIcons.TestImage();
			var bitmap = new Bitmap(new Size(image.Size), PixelFormat.Format32bppRgba);
			var tile = 64; // the test image is 128x128 so this produces 4 tiles.
			using (var g = new Graphics(bitmap))
			{
				for (var x = 0; x < image.Width; x += tile)
					for (var y = 0; y < image.Height; y += tile)
					{
						var clone = image.Clone(new Rectangle(x, y, tile, tile));
						g.DrawImage(clone, x, y);
					}
			}
			return new DrawableImageView { Image = bitmap };
		}
示例#5
0
		void MatrixTests(Graphics g)
		{
			// test matrix RotateAt
			DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) => {
				var m = Matrix.Create();
				m.RotateAt(angle, center);
				g.MultiplyTransform(m);
			});

			// test matrix scale/translate/rotate
			DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) => {
				var m = Matrix.Create();
				m.Translate(center);
				m.Rotate(angle);
				m.Translate(-center);
				m.Scale(.4f);
				g.MultiplyTransform(m);
			});

			// test rotating arcs
			DrawRotatedArcs(g, Colors.LightBlue, rotatedLineCenter, (center, angle) => {
				var m = Matrix.Create();
				m.RotateAt(angle, center);
				g.MultiplyTransform(m);
			});

			// test transformed text
			DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) => {
				var m = Matrix.Create();
				m.RotateAt(angle, center - 40);
				g.MultiplyTransform(m);
			});

			// test image drawing
			{
				g.SaveTransform();
				g.MultiplyTransform(Matrix.FromScaleAt(new SizeF(1, -1), imageScaleLocation + image.Size / 2));
				g.DrawImage(image, imageScaleLocation);

				var m = Matrix.Create();
				m.Translate(0, -50);
				m.ScaleAt(0.3f, imageScaleLocation + image.Size / 2);
				g.MultiplyTransform(m);
				g.DrawImage(image, imageScaleLocation);
				g.RestoreTransform();
			}

			// test skewing
			{
				g.SaveTransform();
				var m = Matrix.Create();
				m.Skew(20, 20);
				g.MultiplyTransform(m);
				var textSize = g.MeasureString(font, "Skewed Text");
				g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text");
				g.DrawLine(Pens.White, 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2);

				g.RestoreTransform();
			}

			// test more drawing operations
			{
				g.SaveTransform();
				var m = Matrix.Create();
				m.Translate(480, 20);
				m.Scale(0.4f);
				m.Rotate(90);
				g.MultiplyTransform(m);
				PixelOffsetSection.Draw(g);
				g.RestoreTransform();
			}
		}
示例#6
0
		void DirectTests(Graphics g)
		{
			// test translate/rotate
			DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) => {
				g.TranslateTransform(center);
				g.RotateTransform(angle);
				g.TranslateTransform(-center);
			});

			// test translate/rotate/scale
			DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) => {
				g.TranslateTransform(center);
				g.RotateTransform(angle);
				g.TranslateTransform(-center);
				g.ScaleTransform(.4f);
			});

			// test rotating arcs
			DrawRotatedArcs(g, Colors.LightBlue, rotatedLineCenter, (center, angle) => {
				g.TranslateTransform(center);
				g.RotateTransform(angle);
				g.TranslateTransform(-center);
			});

			// test transformed text
			DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) => {
				g.TranslateTransform(center - 40);
				g.RotateTransform(angle);
				g.TranslateTransform(-center + 40);
			});

			// Test image drawing
			g.SaveTransform();
			g.TranslateTransform(imageScaleLocation + image.Size / 2);
			g.ScaleTransform(1, -1);
			g.TranslateTransform(-imageScaleLocation - image.Size / 2);
			g.DrawImage(image, imageScaleLocation);

			g.TranslateTransform(0, -50);
			g.TranslateTransform(imageScaleLocation + image.Size / 2);
			g.ScaleTransform(0.3f);
			g.TranslateTransform(-imageScaleLocation - image.Size / 2);
			g.DrawImage(image, imageScaleLocation);
			g.RestoreTransform();

			// test skewing
			g.SaveTransform();
			g.MultiplyTransform(Matrix.FromSkew(20, 20));
			var textSize = g.MeasureString(font, "Skewed Text");
			g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text");
			g.DrawLine(Pens.White, 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2);
			
			g.RestoreTransform();

			// test more drawing operations
			g.SaveTransform();
			g.TranslateTransform(480, 20);
			g.ScaleTransform(0.4f);
			g.RotateTransform(90);
			PixelOffsetSection.Draw(g);
			g.RestoreTransform();
		}
示例#7
0
		Control DrawImageToRect()
		{
			var image64 = TestIcons.Textures;

			var bitmap = new Bitmap(new Size(105, 105), PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				// Draw the "5" portion of the texture at a smaller size at the origin.
				g.DrawImage(image64, new RectangleF(80, 80, 80, 80), new RectangleF(0, 0, 32, 32));
				// draw two rulers to indicate how big the green image should be
				g.SaveTransform();
				g.MultiplyTransform(Matrix.Create(1, 0, 0, 1, 0, 70));
				DrawRuler(32, g, Colors.Blue);
				g.RestoreTransform();

				g.SaveTransform();
				g.MultiplyTransform(Matrix.Create(0, 1, 1, 0, 70, 0));
				DrawRuler(32, g, Colors.Blue);
				g.RestoreTransform();
			}
			return new DrawableImageView { Image = bitmap };
		}
示例#8
0
		Control CloneRectangle()
		{
			var image = TestIcons.TestImage;
			var bitmap = new Bitmap(image.Size, PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				foreach (var tile in GetTiles(image))
				{
					using (var clone = image.Clone(tile))
						g.DrawImage(clone, tile.X, tile.Y);
				}
			}
			return new DrawableImageView { Image = bitmap };
		}
示例#9
0
		public static void Draw(Graphics graphics)
		{
			var image = TestIcons.TestImage;
			// lines
			var whitePen = new Pen(Colors.White, 1);
			graphics.DrawLine(whitePen, 1, 1, 99, 99);
			graphics.DrawLine(whitePen, 50, 1, 50, 99);
			graphics.DrawLine(whitePen, 1, 51, 99, 51);

			graphics.DrawRectangle(whitePen, 101, 1, 100, 100);
			graphics.DrawRectangle(whitePen, 101, 1, 10, 10);

			graphics.DrawEllipse(Pens.Green, 101, 1, 100, 100);

			graphics.DrawPolygon(whitePen, new PointF(203, 1), new PointF(253, 51), new Point(203, 101), new PointF(203, 1), new PointF(253, 1), new PointF(253, 101), new PointF(203, 101));

			var rect = new RectangleF(255, 1, 100, 100);
			graphics.DrawArc(Pens.LightGreen, rect, 180, 90);
			graphics.DrawArc(Pens.SkyBlue, rect, 0, 90);
			rect.Inflate(-15, 0);
			graphics.DrawArc(Pens.FloralWhite, rect, -45, 90);
			rect.Inflate(-5, -20);
			graphics.DrawArc(Pens.SlateGray, rect, -45, 270);
			rect.Inflate(-10, -10);
			graphics.DrawArc(Pens.SteelBlue, rect, 180 + 45, 270);

			graphics.DrawImage(image, 100, 1, 100, 100);

			graphics.DrawText(Fonts.Sans(12 * graphics.PointsPerPixel), Colors.White, 0, 104, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");

			// filled
			graphics.FillRectangle(Brushes.White, 101, 120, 100, 100);
			graphics.FillRectangle(Brushes.Gray, 101, 120, 10, 10);

			graphics.FillEllipse(Brushes.Green, 101, 120, 100, 100);

			graphics.FillPolygon(Brushes.White, new PointF(202, 120), new PointF(252, 170), new Point(202, 220), new PointF(202, 120));

			rect = new RectangleF(255, 120, 100, 100);
			graphics.FillPie(Brushes.LightGreen, rect, 180, 90);
			graphics.FillPie(Brushes.SkyBlue, rect, 0, 90);
			rect.Inflate(-15, 0);
			graphics.FillPie(Brushes.FloralWhite, rect, -45, 90);
			rect.Inflate(-5, -20);
			graphics.FillPie(Brushes.SlateGray, rect, -45, 270);
			rect.Inflate(-10, -10);
			graphics.FillPie(Brushes.SteelBlue, rect, 180 + 45, 270);


			graphics.DrawImage(image, 101, 120, 100, 100);

			const int offset = 440;
			var xoffset = offset;
			var yoffset = 112;
			for (int i = 1; i < 14; i++)
			{
				var pen = new Pen(Colors.White, i);
				pen.LineCap = PenLineCap.Butt;
				graphics.DrawLine(pen, xoffset, 1, xoffset, 110);

				graphics.DrawLine(pen, offset, yoffset, offset + 100, yoffset);

				xoffset += i + 2;
				yoffset += i + 2;
			}

		}
示例#10
0
		Control DrawImageToRect()
		{
			var image64 = TestIcons.Textures;

			var size = new Size(105, 105) * (int)Screen.PrimaryScreen.LogicalPixelSize;
			var bitmap = new Bitmap(size, PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				g.PixelOffsetMode = PixelOffsetMode.Half;
				g.ScaleTransform(Screen.PrimaryScreen.LogicalPixelSize, Screen.PrimaryScreen.LogicalPixelSize);

				// Draw the "5" portion of the texture at a smaller size at the origin.
				g.DrawImage(image64, new RectangleF(80, 80, 80, 80), new RectangleF(0, 0, 32, 32));
				// draw two rulers to indicate how big the green image should be
				g.SaveTransform();
				g.MultiplyTransform(Matrix.Create(1, 0, 0, 1, 0.5f, 70.5f));
				DrawRuler(32, g, Colors.Blue);
				g.RestoreTransform();

				g.SaveTransform();
				g.MultiplyTransform(Matrix.Create(0, 1, 1, 0, 70.5f, 0.5f));
				DrawRuler(32, g, Colors.Blue);
				g.RestoreTransform();
			}
			return new DrawableImageView { Image = new Icon(Screen.PrimaryScreen.LogicalPixelSize, bitmap) };
		}