Ejemplo n.º 1
0
		public static void DrawString(ref OffsetImage target, string text, SizeF stringSize, Font font, Brush brush, RotateMatrix rm)
		{
			//RotateMatrix rm = RenderHelper.Rotate(angle, stringSize.Width / 2, stringSize.Height / 2, stringSize.Width, stringSize.Height, 1, 1, 0, 0, drawOffsetX, drawOffsetY);
			Bitmap imgstr = new Bitmap((int)stringSize.Width, (int)stringSize.Height);
			Graphics gstr = Graphics.FromImage(imgstr);
			gstr.DrawString(text, font, brush, new PointF(0, 0));
			DrawImage(ref target, imgstr, rm);
		}
Ejemplo n.º 2
0
		public static void DrawString(ref OffsetImage target, string text, Font font, Brush brush, RotateMatrix rm)
		{
			SizeF size = new SizeF();
			Bitmap img = new Bitmap(1, 1);
			Graphics g = Graphics.FromImage(img);
			size = g.MeasureString(text, font);
			DrawString(ref target, text, size, font, brush, rm);
		}
Ejemplo n.º 3
0
		public static void DrawString(Graphics g, OffsetImage target, string text, Font font, Brush brush, RotateMatrix matrix, PointF location)
		{
			if (g != null)
			{
				g = Graphics.FromImage(new Bitmap(1, 1));
			}
			SizeF sz = g.MeasureString(text, font);
			Bitmap iTemp = new Bitmap((int)sz.Width, (int)sz.Height);
			Graphics gTemp = Graphics.FromImage(iTemp);
			gTemp.DrawString(text, font, brush, 0, 0);
			gTemp.Dispose();
			DrawImage(ref target, iTemp, matrix);
			DrawImage(g, target, location);
		}
Ejemplo n.º 4
0
		public static void DrawImage(ref OffsetImage oi, OffsetImage content, RotateMatrix matrix)
		{
			//oi.Matrix = matrix;
			content.Matrix = matrix;
			content.RenderedSource = DrawImage(ref oi.Source, content.Source, matrix);
		}
Ejemplo n.º 5
0
		public static RotateMatrix Rotate(
			double angle
			, double centerX
			, double centerY
			, double width
			, double height
			, double scaleX
			, double scaleY
			, double shearX
			, double shearY
			, double drawOffsetX
			, double drawOffsetY
		)
		{
			float angleF = (float)angle;
			float centerXF = (float)centerX;
			float centerYF = (float)centerY;
			float widthF = (float)width;
			float heightF = (float)height;
			float scaleXF = (float)scaleX;
			float scaleYF = (float)scaleY;
			float shearXF = (float)shearX;
			float shearYF = (float)shearY;
			float drawOffsetXF = (float)drawOffsetX;
			float drawOffsetYF = (float)drawOffsetY;

			PointF offset = new PointF();
			PointF ur = new PointF();
			Matrix matrix = new Matrix();
			PointF center = new PointF(centerXF, centerYF);
			angleF = angleF % 360;
			if (angleF < 0)
			{
				angleF += 360;
			}
			if (angleF % 90 == 0)
			{
				angleF += 0.01f;
			}

			widthF = centerXF * 2 * scaleXF;
			heightF = centerYF * 2 * scaleYF;
			matrix.Scale(scaleXF, scaleYF);
			matrix.Shear(shearXF, shearYF);
			matrix.RotateAt(angleF, center);

			offset.X = matrix.OffsetX;
			offset.Y = matrix.OffsetY;
			float rs, rc;
			rs = (float)Math.Sin(angleF * Math.PI / 180);
			rc = (float)Math.Cos(angleF * Math.PI / 180);
			ur.X = rc * widthF;
			ur.Y = rs * widthF;
			ur.X += matrix.OffsetX;
			ur.Y += matrix.OffsetY;
			angleF = angleF % 360;
			if (angleF >= 0 && angleF <= 90)
			{
				offset.X = ur.X - widthF;
				offset.Y = -matrix.OffsetY;
			}
			else if (angleF > 90 && angleF < 180)
			{
				offset.X = -widthF + matrix.OffsetX;
				offset.Y = ur.Y - heightF;
			}
			else if (angleF >= 180 && angleF <= 270)
			{
				offset.X = -ur.X;
				offset.Y = matrix.OffsetY - heightF;
			}
			else
			{
				offset.X = -matrix.OffsetX;
				offset.Y = -ur.Y;
			}

			matrix.RotateAt(-angleF, center);
			matrix.Translate(offset.X / scaleXF, offset.Y / scaleYF);
			//matrix.Translate(offset.X / scaleXF + drawOffsetXF / scaleXF, offset.Y / scaleYF + drawOffsetYF / scaleYF);
			matrix.RotateAt(angleF, center);
			RotateMatrix rm = new RotateMatrix(matrix, angleF, -offset.X, -offset.Y, widthF, heightF);
			rm.AbsoluteOffset = new PointF(drawOffsetXF, drawOffsetYF);
			return rm;
		}
Ejemplo n.º 6
0
		public static Bitmap DrawImage(ref Bitmap target, Bitmap content, RotateMatrix matrix)
		{
			Bitmap temp = null;
			try
			{
				if (matrix.IsBiggerEqualTo(target.Size))
				{
					target.Dispose();
					target = matrix.GetNewImage();
				}
				temp = new Bitmap((int)matrix.ActualSize.Width, (int)matrix.ActualSize.Height);
				PointF offsetPoint = new PointF(matrix.AbsoluteOffset.X + matrix.RelativeOffset.X, matrix.AbsoluteOffset.Y + matrix.RelativeOffset.Y);
				Graphics g = Graphics.FromImage(temp);
				g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
				g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
				g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
				g.Transform = matrix.Matrix;
				g.DrawImage(content, new Point(0, 0));
				if (DrawActualBounds)
				{
					g.DrawRectangle(Pens.Red, 0, 0, content.Width, content.Height);
				}
				g.Dispose();
				g = Graphics.FromImage(target);
				g.DrawImage(temp, offsetPoint);
				if (DrawActualBounds)
				{
					g.DrawRectangle(Pens.Maroon, offsetPoint.X, offsetPoint.Y, matrix.ActualSize.Width, matrix.ActualSize.Height);
				}
				g.Dispose();
			}
			catch (Exception e)
			{
				Exceptions.LogOnly(e);
			}
			return temp;
		}
Ejemplo n.º 7
0
		public static void DrawImage(ref OffsetImage oi, Bitmap content, RotateMatrix matrix)
		{
			DrawImage(ref oi.Source, content, matrix);
		}