// public virtual void OnRender(Graphics g) // { //#if !PocketPC // if (IsVisible) // { // if (graphicsPath != null) // { // try // { // // g.SmoothingMode = SmoothingMode.HighQuality; // if (_routeStyle.Count == 0) // { // g.DrawPath(Stroke, graphicsPath); // return; // } // foreach (RouteStyle rs in _routeStyle) // { // if (rs.Name == "UpStyle") // { // updateUpPath(rs.StyleOffset); // Pen nP = new Pen(rs.RouteColor, rs.RouteWidth); // if (rs.RouteDash == DashStyle.Custom) // { // nP.DashPattern = rs.DashPattern; // } // else // { // nP.DashStyle = rs.RouteDash; // } // g.DrawPath(nP, graphicsStyleUpPath); // } // else if (rs.Name == "DownStyle") // { // updateDownPath(rs.StyleOffset); // Pen nP = new Pen(rs.RouteColor, rs.RouteWidth); // if (rs.RouteDash == DashStyle.Custom) // { // nP.DashPattern = rs.DashPattern; // } // else // { // nP.DashStyle = rs.RouteDash; // } // g.DrawPath(nP, graphicsStyleDownPath); // } // else if (rs.Name == "MiddleStyle") // { // Pen nP = new Pen(rs.RouteColor, rs.RouteWidth); // if (rs.RouteDash == DashStyle.Custom) // { // nP.DashPattern = rs.DashPattern; // } // else // { // nP.DashStyle = rs.RouteDash; // } // g.DrawPath(nP, graphicsPath); // } // } // } // catch // { // } // } // } //#else // if (IsVisible) // { // Point[] pnts = new Point[LocalPoints.Count]; // for (int i = 0; i < LocalPoints.Count; i++) // { // Point p2 = new Point((int)LocalPoints[i].X, (int)LocalPoints[i].Y); // pnts[pnts.Length - 1 - i] = p2; // } // if (pnts.Length > 1) // { // g.DrawLines(Stroke, pnts); // } // } //#endif // } public virtual void OnRender(Graphics g) { #if !PocketPC if (IsVisible) { if (graphicsPath != null) { try { if (_listImage.Count == 0) { g.DrawPath(Stroke, graphicsPath); } else { for (int i = 0; i < graphicsPath.PathPoints.Length - 1; i++) { TextureBrush tb = new TextureBrush(_listImage[0], WrapMode.TileFlipXY); PointF p1 = graphicsPath.PathPoints[i]; PointF p2 = graphicsPath.PathPoints[i + 1]; if (p1.X == p2.X) { tb.RotateTransform(90, MatrixOrder.Prepend); } else { double angle = Math.Atan((p2.Y - p1.Y) / (p2.X - p1.X)); float aa = (float)(angle * 180 / Math.PI); tb.RotateTransform(aa, MatrixOrder.Prepend); } Pen np = new Pen(tb, 10); g.DrawLine(np, p1, p2); // g.DrawPath(np, graphicsPath); } } } catch { } } } #else if (IsVisible) { Point[] pnts = new Point[LocalPoints.Count]; for (int i = 0; i < LocalPoints.Count; i++) { Point p2 = new Point((int)LocalPoints[i].X, (int)LocalPoints[i].Y); pnts[pnts.Length - 1 - i] = p2; } if (pnts.Length > 1) { g.DrawLines(Stroke, pnts); } } #endif }
public void RotateTransform_Disposed_ThrowsArgumentException() { using (var image = new Bitmap(10, 10)) using (var matrix = new Matrix()) { var brush = new TextureBrush(image); brush.Dispose(); AssertExtensions.Throws <ArgumentException>(null, () => brush.RotateTransform(1)); AssertExtensions.Throws <ArgumentException>(null, () => brush.RotateTransform(1, MatrixOrder.Prepend)); } }
private void label1_Paint(object sender, PaintEventArgs e) { if (this.strfilename.Trim() == "") { return; } try { Bitmap mybitmap = new Bitmap(strfilename); Graphics g = e.Graphics; TextureBrush mybrush = new TextureBrush(mybitmap); float x = (float)(numericUpDownS1.Value / 100); float y = (float)(numericUpDownS2.Value / 100); mybrush.ScaleTransform(x, y); g.FillRectangle(mybrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height); float r = (float)(numericUpDownR1.Value); mybrush.RotateTransform(r); g.FillRectangle(mybrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height); float tx = (float)(numericUpDownT1.Value); float ty = (float)(numericUpDownT2.Value); mybrush.TranslateTransform(tx, ty); g.FillRectangle(mybrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height); } catch (Exception Err) { MessageBox.Show("Open File Error. ", "Informatin .", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; Image bm = Bitmap.FromFile(@"heart.ico"); TextureBrush brush = new TextureBrush(bm); Random rnd = new Random(); g.FillRectangle( new LinearGradientBrush( new PointF(0, 0), new PointF(Width, Height), Color.Black, Color.White), 0, 0, Width, Height); brush.TranslateTransform(-8, -8); for (int i = 0; i < 10; i++) { brush.RotateTransform(rnd.Next(360)); g.FillRectangle( brush, i * 60, 0, 50, Height); } }
private void TextureBrush_Click(object sender, System.EventArgs e) { Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); // Create a TextureBrush object TextureBrush txtrBrush = new TextureBrush( new Bitmap("smallRoses.gif")); // Create a transformation matrix. Matrix M = new Matrix(); // Rotate the texture image by 90 degrees. txtrBrush.RotateTransform(90, MatrixOrder.Prepend); // Translate M.Translate(50, 0); // Multiply the transformation matrix // of tBrush by translateMatrix. txtrBrush.MultiplyTransform(M); // Scale operation txtrBrush.ScaleTransform(2, 1, MatrixOrder.Prepend); // Fill a rectangle with texture brush g.FillRectangle(txtrBrush, 240, 0, 200, 200); // Reset transformation txtrBrush.ResetTransform(); // Fill rectangle after reseting transformation g.FillRectangle(txtrBrush, 0, 0, 200, 200); // Dispose txtrBrush.Dispose(); g.Dispose(); }
void CreateNewTextureBrush() { brush = new TextureBrush(new Bitmap(imagePath)); brush.RotateTransform(45); brush.ScaleTransform(1.5f, 1.25f); brush.TranslateTransform(150, 150); }
public void RotateTransform() { TextureBrush t = new TextureBrush(image); t.RotateTransform(90); float[] elements = t.Transform.Elements; Assert.AreEqual(0, elements[0], 0.1, "matrix.0"); Assert.AreEqual(1, elements[1], 0.1, "matrix.1"); Assert.AreEqual(-1, elements[2], 0.1, "matrix.2"); Assert.AreEqual(0, elements[3], 0.1, "matrix.3"); Assert.AreEqual(0, elements[4], 0.1, "matrix.4"); Assert.AreEqual(0, elements[5], 0.1, "matrix.5"); t.RotateTransform(270); Assert.IsTrue(t.Transform.IsIdentity, "Transform.IsIdentity"); }
public override Brush GetBrush() { Brush brush = base.GetBrush(); if (Picture == null) { return(brush); } if (Scale.X == 0 || Scale.Y == 0) { return(brush); } if (Scale.X * Picture.Width * Scale.Y * Picture.Height > 8000 * 8000) { return(brush); // The scaled image is too large, will cause memory exceptions. } if (Picture != null) { Bitmap scaledBitmap = new Bitmap((int)(Picture.Width * Scale.X), (int)(Picture.Height * Scale.Y)); Graphics scb = Graphics.FromImage(scaledBitmap); scb.DrawImage(Picture, new Rectangle(0, 0, scaledBitmap.Width, scaledBitmap.Height), new Rectangle(0, 0, Picture.Width, Picture.Height), GraphicsUnit.Pixel); TextureBrush tb = new TextureBrush(scaledBitmap, WrapMode); tb.RotateTransform(-Angle); brush = tb; } return(brush); }
private void StandardDemo1Ctl_Load(object sender, System.EventArgs e) { Stream stm = Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoTreeView.images.fond1.jpg"); Image bmp = Bitmap.FromStream(stm); geniusTreeView1.Header.Colonnes.Clear(); GeniusTreeViewColonne col = geniusTreeView1.Header.Add(); col.AllowClick = false; col.BackColor = new GeniusLinearGradientBrush(Color.White, Color.LightBlue, 90); col.ForeColor = new GeniusLinearGradientBrush(Color.White, Color.Black, 90); col.Font = new Font("Tahoma", 13, FontStyle.Bold | FontStyle.Italic); col.Text = "Image file name"; col.Width = 218; col = geniusTreeView1.Header.Add(); col.AllowClick = false; col.Text = "Thumbnail"; col.Width = 160; col = geniusTreeView1.Header.Add(); col.AllowClick = false; col.Text = "Properties"; col.Width = 120; TextureBrush br = new TextureBrush(bmp, WrapMode.Tile); br.RotateTransform(25); //br.ScaleTransform(2,2,MatrixOrder.Append); col.BackColor = new GeniusLinearGradientBrush(br); geniusTreeView1.DefaultNodeHeight = 32; geniusTreeView1.Colors.GridLinesColor = new Pen(Color.LightGray, 1); geniusTreeView1.Header.MainColumnIndex = 0; }
public void RotateTransform_Invoke_SetsTransformToExpected(Matrix originalTransform, float angle, MatrixOrder matrixOrder) { try { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) using (Matrix expected = originalTransform.Clone()) { expected.Rotate(angle, matrixOrder); brush.Transform = originalTransform; if (matrixOrder == MatrixOrder.Prepend) { TextureBrush clone = (TextureBrush)brush.Clone(); clone.RotateTransform(angle); Assert.Equal(expected, clone.Transform); } brush.RotateTransform(angle, matrixOrder); Assert.Equal(expected, brush.Transform); } } finally { originalTransform.Dispose(); } }
/// <summary> /// Instructs the drawing code to fill the specified path with the specified image. /// </summary> /// <param name="g">The Graphics device to draw to</param> /// <param name="gp">The GraphicsPath to fill</param> public override void FillPath(Graphics g, GraphicsPath gp) { if (_picture == null) { return; } if (_scale.X == 0 || _scale.Y == 0) { return; } if (_scale.X * _picture.Width * _scale.Y * _picture.Height > 8000 * 8000) { return; // The scaled image is too large, will cause memory exceptions. } Bitmap scaledBitmap = new Bitmap((int)(_picture.Width * _scale.X), (int)(_picture.Height * _scale.Y)); Graphics scb = Graphics.FromImage(scaledBitmap); scb.DrawImage(_picture, new Rectangle(0, 0, scaledBitmap.Width, scaledBitmap.Height), new Rectangle(0, 0, _picture.Width, _picture.Height), GraphicsUnit.Pixel); TextureBrush tb = new TextureBrush(scaledBitmap, _wrapMode); tb.RotateTransform(-(float)_angle); g.FillPath(tb, gp); tb.Dispose(); scb.Dispose(); base.FillPath(g, gp); }
public void RotateTransform_InvalidOrder() { Assert.Throws <ArgumentException>(() => { TextureBrush t = new TextureBrush(image); t.RotateTransform(720, (MatrixOrder)Int32.MinValue); }); }
public void RotateTransform_InvalidOrder_ThrowsArgumentException(MatrixOrder matrixOrder) { using (var image = new Bitmap(10, 10)) using (var brush = new TextureBrush(image)) { AssertExtensions.Throws <ArgumentException>(null, () => brush.RotateTransform(10, matrixOrder)); } }
public void ResetTransform() { TextureBrush t = new TextureBrush(image); t.RotateTransform(90); Assert.IsFalse(t.Transform.IsIdentity, "Transform.IsIdentity"); t.ResetTransform(); Assert.IsTrue(t.Transform.IsIdentity, "Reset.IsIdentity"); }
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { using (TextureBrush br = new TextureBrush(bmp, WrapMode.Tile)) { br.RotateTransform(25); GeniusLinearGradientBrush gbr = new GeniusLinearGradientBrush(br); e.Graphics.FillRectangle(gbr.GetBrush(this.DisplayRectangle), this.DisplayRectangle); } }
public void TextureBush_10() { TextureBrush b = new TextureBrush(bmp, WrapMode.TileFlipXY, new Rectangle(100, 100, 50, 50)); t.Graphics.RotateTransform(30); b.RotateTransform(30); t.Graphics.FillRectangle(b, 100, 100, 300, 300); t.Show(); Assert.IsTrue(t.PDCompare()); }
// </snippet5> // Snippet for: M:System.Drawing.TextureBrush.RotateTransform(System.Single,System.Drawing.Drawing2D.MatrixOrder) // <snippet6> public void RotateTransform_Example2(PaintEventArgs e) { // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); // Rotate the texture image by 90 degrees. tBrush.RotateTransform(90, MatrixOrder.Prepend); // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); }
/// <summary> /// 自动旋转 /// </summary> /// <param name="bmp">Bitmap 对象</param> /// <param name="picBox">PictureBox 对象</param> public static void XuanZhuan(Bitmap MyBitmap, PictureBox picBox) { Graphics g = picBox.CreateGraphics(); float MyAngle = 0;//旋转的角度 while (MyAngle < 360) { TextureBrush MyBrush = new TextureBrush(MyBitmap); picBox.Refresh(); MyBrush.RotateTransform(MyAngle); g.FillRectangle(MyBrush, 0, 0, MyBitmap.Width, MyBitmap.Height); MyAngle += 0.5f; System.Threading.Thread.Sleep(50); } }
private void textBox1_TextChanged(object sender, EventArgs e) { try { float f = Single.Parse(rotationTextBox.Text); tb.RotateTransform(f); rotationTextBox.BackColor = SystemColors.Window; } catch { rotationTextBox.BackColor = Color.Red; } finally { Invalidate(); Update(); } }
private void button1_Click(object sender, EventArgs e) { Graphics g = this.panel1.CreateGraphics(); //实例化绘图对象 float MyAngle = 0; //旋转的角度 while (MyAngle < 360) { TextureBrush MyBrush = new TextureBrush(MyBitmap); //实例化TextureBrush类 this.panel1.Refresh(); //使工作区无效 MyBrush.RotateTransform(MyAngle); //以指定角度旋转图像 g.FillRectangle(MyBrush, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); //绘制旋转后的图像 MyAngle += 0.5f; //增加旋转的角度 System.Threading.Thread.Sleep(50); //使线程休眠50毫秒 } }
// </snippet3> // Snippet for: M:System.Drawing.TextureBrush.ResetTransform // <snippet4> public void ResetTransform_Example(PaintEventArgs e) { // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); // Rotate the texture image by 90 degrees. tBrush.RotateTransform(90); // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); // Reset transformation matrix to identity. tBrush.ResetTransform(); // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 110, 100, 100); }
public static bool MarkImage(WatermarkArgs watermarkArgs) { try { var baseImageName = watermarkArgs.InputBaseImage; var waterImageName = watermarkArgs.InputWaterImage; var outputImageName = watermarkArgs.OutputImage; var waterScale = watermarkArgs.WaterScale; if (File.Exists(outputImageName) && watermarkArgs.ForceWrite == false) { _Log.WriteWarning($"File already exists! Cancelling operation for {outputImageName}"); return(false); } using (var baseImage = Image.FromFile(baseImageName)) using (var waterImage = Image.FromFile(waterImageName)) using (var baseGraphics = Graphics.FromImage(baseImage)) using (var waterBrush = new TextureBrush(waterImage, System.Drawing.Drawing2D.WrapMode.Tile)) { waterBrush.RotateTransform(-45); waterBrush.ScaleTransform((float)waterScale, (float)waterScale); baseGraphics.FillRectangle(waterBrush, new Rectangle( new Point(0, 0), new Size(baseImage.Width, baseImage.Height) )); baseImage.Save(outputImageName, ImageFormat.Png); } watermarkArgs.ParentTask?.IncrementProgress(); return(true); } catch (Exception exception) { _Log.WriteException(exception); } return(false); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (iWaiting) { int x = (int)((ClientRectangle.Width - kImageWaiting.Width) * 0.5f); int y = (int)((ClientRectangle.Height - kImageWaiting.Height) * 0.5f); e.Graphics.DrawImage(kImageWaiting, x, y); iTextureBrush.ResetTransform(); iTextureBrush.TranslateTransform(x, y); iTextureBrush.TranslateTransform(kImageWaiting.Width * 0.5f, kImageWaiting.Height * 0.5f); iTextureBrush.RotateTransform(iAngle); iTextureBrush.TranslateTransform(-kImageWaiting.Width * 0.5f, -kImageWaiting.Height * 0.5f); e.Graphics.FillRectangle(iTextureBrush, x, y, kImageWaiting.Width, kImageWaiting.Height); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; e.Graphics.DrawString(iMessage, Font, iBrushForeColour, new Rectangle(0, y + 75, ClientSize.Width, Font.Height), format); } }
public static Bitmap GetRotateImage(Bitmap Image, float w, float h, double t) { float dw = w * 2.0f; float dh = h * 2.0f; Bitmap RotateBmp = new Bitmap((int)(dw + 0.5), (int)(dh + 0.5)); Graphics gp = Graphics.FromImage(RotateBmp); { TextureBrush TextureFill = new TextureBrush(Image); TextureFill.RotateTransform((float)(t * 180.0 / Math.PI)); double dx = 0, dy = 0; double dPI = Math.PI / 2.0; if (0 < t && t < dPI || Math.PI < t && t < (Math.PI + dPI)) { dx = 0; dy = dh * Math.Cos(-t); } else if (dPI < t && t < Math.PI || (Math.PI + dPI) < t && t < (Math.PI + Math.PI)) { dx = dw * Math.Cos(-t); dy = 0; } TextureFill.TranslateTransform((float)dx, (float)dy); gp.FillRectangle(TextureFill, 0, 0, dw, dh); TextureFill.Dispose(); gp.Dispose(); } return(RotateBmp); }
public void Redraw() { //float xScl = 0, yScl = 0; this._drawing = true; try { // Use a bitmap object for drawing. This prevents the flicker. using (Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height)) { // Create a Graphics object to draw into the bitmap object. using (Graphics gBmp = Graphics.FromImage(bmp)) { if (_mSamp) { gBmp.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; gBmp.CompositingQuality = this._compQual; gBmp.InterpolationMode = this._intrpQual; gBmp.SmoothingMode = this._smthMode; } // Create a brush to use for drawing the control's background. Brush backBrush = null; Bitmap bgImg = null; { // Calculate the center of the control's client area. int xCen = this.ClientRectangle.Width / 2, yCen = this.ClientRectangle.Height / 2; // Draw the background, effectively erasing the control. // First, we need to clear the image to the proper // background color. gBmp.Clear(this.BackColor); // Then draw the background image, if there is one. if (this.BackgroundImage != null) { // If the control has a background image, we need to draw // that image instead of the background color. bgImg = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); using (Graphics gBg = Graphics.FromImage(bgImg)) { // Clear the bgImg with the backcolor. gBg.Clear(this.BackColor); // Get a texture brush to draw the control's // background image onto. using (TextureBrush tBrush = new TextureBrush(this.BackgroundImage)) { // Determine the image layout. switch (this.BackgroundImageLayout) { case ImageLayout.None: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; } break; case ImageLayout.Tile: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; } break; case ImageLayout.Zoom: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; Rectangle drawSize = RainstormStudios.Drawing.Imaging.ZoomImage(this.BackgroundImage, this.ClientRectangle); tBrush.TranslateTransform(drawSize.X, drawSize.Y); tBrush.ScaleTransform(((float)drawSize.Width) / ((float)this.BackgroundImage.Width), ((float)drawSize.Height) / ((float)this.BackgroundImage.Height)); //xScl = ((float)drawSize.Width) / ((float)this.BackgroundImage.Width); //yScl = ((float)drawSize.Height) / ((float)this.BackgroundImage.Height); } break; case ImageLayout.Stretch: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; tBrush.ScaleTransform(((float)this.ClientRectangle.Width) / ((float)this.BackgroundImage.Width), ((float)this.ClientRectangle.Height) / ((float)this.BackgroundImage.Height)); //xScl = ((float)this.ClientRectangle.Width) / ((float)this.BackgroundImage.Width); //yScl = ((float)this.ClientRectangle.Height) / ((float)this.BackgroundImage.Height); } break; case ImageLayout.Center: { tBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp; Point drawPoint = RainstormStudios.Drawing.Imaging.CenterImage(this.BackgroundImage, this.ClientRectangle); tBrush.TranslateTransform(drawPoint.X, drawPoint.Y); } break; } if (this._bgRot != 0) { tBrush.RotateTransform(this._bgRot); // Rotation is done at the top-left corner, so to // keep the image centered, we have to adjust // the translation transformation. // TODO:: Will determine how to do this later. } gBg.FillRectangle(tBrush, 0, 0, bgImg.Width, bgImg.Height); } } backBrush = new TextureBrush(bgImg); gBmp.FillRectangle(backBrush, this.ClientRectangle); } else { // If there's no background image, then just set the // background brush to the background color. backBrush = new SolidBrush(this.BackColor); } // Create a brush using the control's ForeColor and draw a // circle padded 5px from the control's client area on all sides. using (SolidBrush foreBrush = new SolidBrush(this.ForeColor)) gBmp.FillEllipse(foreBrush, this.ClientRectangle.X + 5, this.ClientRectangle.Y + 5, this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10); // If the designer specified a center hole "punch-out", // draw another circle with the background brush. if (_inrDiam > 0) { // Calculate the inner circle size/position. Point inrOrig = new Point((bmp.Width / 2) - _inrDiam, (bmp.Height / 2) - _inrDiam); Size inrSize = new Size(bmp.Width - (((bmp.Width / 2) - _inrDiam) * 2), bmp.Height - (((bmp.Height / 2) - _inrDiam) * 2)); Rectangle inrRect = new Rectangle(inrOrig, inrSize); // Draw the Ellipse. gBmp.FillEllipse(backBrush, inrRect); // Clear the size/position objects to release memory. inrRect = Rectangle.Empty; inrOrig = Point.Empty; inrSize = Size.Empty; } //if (_holeWidth > 0) // gBmp.FillEllipse(backBrush, (this.ClientRectangle.X / 2) - _holeWidth, (this.ClientRectangle.Y / 2) - _holeWidth, _holeWidth * 2, _holeWidth * 2); // Calculate the 'orbital' positions around the center of the control // that the lines will be drawn to. int[] t = new int[_lineCnt]; double[] a = new double[_lineCnt]; double[] xPos = new double[_lineCnt]; double[] yPos = new double[_lineCnt]; using (Pen penLine = new Pen(backBrush, _penWidth)) { for (int i = 0; i < _lineCnt; i++) { t[i] = _t + (i * ((base_prec * _prec) / _lineCnt)); if (t[i] > (base_prec * _prec)) { t[i] = t[i] - (base_prec * _prec); } a[i] = System.Math.PI * t[i] / ((base_prec * _prec) / 2); if (_funk) { if (i % 2 > 0) { xPos[i] = xCen + (this.ClientRectangle.Width / 2) * System.Math.Sin(a[i]); yPos[i] = (yCen * (this.ClientRectangle.Height / 2) * System.Math.Cos(a[i])) / 2; } else { xPos[i] = (xCen * (this.ClientRectangle.Width / 2) * System.Math.Sin(a[i])) / 2; yPos[i] = yCen + (this.ClientRectangle.Height / 2) * System.Math.Cos(a[i]); } } else { xPos[i] = xCen + (this.ClientRectangle.Width / 2) * System.Math.Sin(a[i]); yPos[i] = yCen + (this.ClientRectangle.Height / 2) * System.Math.Cos(a[i]); } gBmp.DrawLine(penLine, (float)xCen, (float)yCen, (float)xPos[i], (float)yPos[i]); } } } // DEBUG: Draw the transform values: //gBmp.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.ClientRectangle.Width, 15); //gBmp.DrawString("Transform: x=" + xScl.ToString() + "/y=" + yScl.ToString() + " Offset: x=" + ((TextureBrush)backBrush).Transform.OffsetX + "/y=" + ((TextureBrush)backBrush).Transform.OffsetY + " Elements: " + AosConvert.ConcatArray(((TextureBrush)backBrush).Transform.Elements, ","), this.Font, SystemBrushes.ControlText, this.ClientRectangle.Location); backBrush.Dispose(); if (bgImg != null) { bgImg.Dispose(); } // Finally, create a Graphics object to draw the Bitmap to the control. using (Graphics g = this.CreateGraphics()) g.DrawImageUnscaled(bmp, new Point(0, 0)); } } } finally { this._drawing = false; } }
private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 char[] NUMBER = new char[36] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; Random dd = new Random(Environment.TickCount); string number1 = NUMBER[dd.Next(36)].ToString(); string number2 = NUMBER[dd.Next(36)].ToString(); string number3 = NUMBER[dd.Next(36)].ToString(); string number4 = NUMBER[dd.Next(36)].ToString(); string number = number1 + number2 + number3 + number4; Session["ValidateID"] = number; using (Bitmap map = new Bitmap(80, 30)) { using (Graphics image = Graphics.FromImage(map)) { image.Clear(Color.Black); using (Bitmap tmpMap = new Bitmap(20, 30)) { using (Graphics g = Graphics.FromImage(tmpMap)) { g.DrawString(number1, new Font("新宋体", 18), Brushes.LightYellow, 0, 0); TextureBrush tb = new TextureBrush(tmpMap, WrapMode.Tile); tb.RotateTransform(dd.Next(14) - 7); image.FillRectangle(tb, 0, 0, 20, 30); } } using (Bitmap tmpMap = new Bitmap(20, 30)) { using (Graphics g = Graphics.FromImage(tmpMap)) { g.DrawString(number2, new Font("新宋体", 18), Brushes.LightYellow, 0, 0); TextureBrush tb = new TextureBrush(tmpMap, WrapMode.Tile); tb.RotateTransform(dd.Next(14) - 7); tb.TranslateTransform(0.00f, 1.00f); image.FillRectangle(tb, 20, 0, 20, 30); } } using (Bitmap tmpMap = new Bitmap(20, 30)) { using (Graphics g = Graphics.FromImage(tmpMap)) { g.DrawString(number3, new Font("新宋体", 18), Brushes.LightYellow, 0, 0); TextureBrush tb = new TextureBrush(tmpMap, WrapMode.Tile); tb.RotateTransform(dd.Next(14) - 7); tb.TranslateTransform(0.00f, 2.00f); image.FillRectangle(tb, 40, 0, 20, 30); } } using (Bitmap tmpMap = new Bitmap(20, 30)) { using (Graphics g = Graphics.FromImage(tmpMap)) { g.DrawString(number4, new Font("新宋体", 18), Brushes.LightYellow, 0, 0); TextureBrush tb = new TextureBrush(tmpMap, WrapMode.Tile); tb.RotateTransform(dd.Next(14) - 7); tb.TranslateTransform(0.00f, 3.00f); image.FillRectangle(tb, 60, 0, 20, 30); } } for (int i = 0; i < 30; i++) { map.SetPixel(dd.Next(80), dd.Next(30), System.Drawing.Color.White); } map.Save(this.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); } } }
public void RotateTransform_InvalidOrder() { TextureBrush t = new TextureBrush(image); t.RotateTransform(720, (MatrixOrder)Int32.MinValue); }
/// <summary> /// Creates a .NET brush based on the current brush specification, /// optionally flipping the start and end colors. /// </summary> public static Brush MakeBrush(this LogicalBrush data, Rectangle bounds, bool reverse) { // Validate if (data == null) { throw new ArgumentNullException(nameof(data)); } // Make brush (according to type) switch (data.BrushType) { case LogicalBrushType.SingleColor: { // Single Color if (!data.StartColor.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.StartColor))); } return(new SolidBrush(Color.FromArgb(data.StartColor.Value))); } case LogicalBrushType.TwoColorGradient: { // Two color gradient if (!data.StartColor.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.StartColor))); } if (!data.EndColor.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.EndColor))); } if (!data.Angle.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.Angle))); } Color startColor, endColor; if (reverse) { startColor = Color.FromArgb(data.EndColor.Value); endColor = Color.FromArgb(data.StartColor.Value); } else { startColor = Color.FromArgb(data.StartColor.Value); endColor = Color.FromArgb(data.EndColor.Value); } return(new LinearGradientBrush(bounds, startColor, endColor, Decimal.ToSingle(data.Angle.Value))); } case LogicalBrushType.Texture: { // Texture if (!data.Angle.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.Angle))); } if (!data.WrapMode.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.WrapMode))); } if (!data.Scale.HasValue) { throw new ArgumentNullException( String.Format(CultureInfo.CurrentCulture, Resources.PropertyRequired, nameof(LogicalBrush.Scale))); } // Make texture Image image; using (var reader = new MemoryStream(data.Texture)) image = Image.FromStream(reader); var brush = new TextureBrush(image, (WrapMode)(int)data.WrapMode.Value); // Rotate brush.RotateTransform(Decimal.ToSingle(data.Angle.Value), MatrixOrder.Append); // Scale image to fit var scaleX = 1.0F; if (image.Width > bounds.Width) { scaleX = bounds.Width / (float)image.Width; } var scaleY = 1.0F; if (image.Height > bounds.Height) { scaleY = bounds.Height / (float)image.Height; } var fScale = 1.0F; if ((scaleX < 1) || (scaleY < 1)) { fScale = scaleX < scaleY ? scaleX : scaleY; } // Scale image var fFinalScale = data.Scale.Value * fScale; brush.ScaleTransform(fFinalScale, fFinalScale, MatrixOrder.Append); // Return result return(brush); } default: // Unsupported type throw new NotSupportedException(); } }
private void CreateOrnament_Click(object sender, EventArgs e) { if (gw != null) { gw.Close(); } gw = new GeneratedWindow(); var fix = typeBox.SelectedIndex; var six = shirtBox.SelectedIndex; string text = nameBox.Text.ToLower().Trim(); if (text.IndexOf(' ') >= 0) { MessageBox.Show("Please, remove spaces!"); return; } if (text.Length == 0) { MessageBox.Show("Please, enter a word!"); return; } board.Clear(); board.setWord(text); var imageSize = 609; var bsize = imageSize / (board.getMaxValue() * 2); var spoint = imageSize / 2; SolidBrush redBrush = new SolidBrush(Color.FromArgb(255, foundings[fix].redColor.R, foundings[fix].redColor.G, foundings[fix].redColor.B)); SolidBrush blackBrush = new SolidBrush(Color.FromArgb(255, foundings[fix].blackColor.R, foundings[fix].blackColor.G, foundings[fix].blackColor.B)); SolidBrush grayBrush = new SolidBrush(Color.Gray); var bmp = new Bitmap(imageSize, imageSize); Graphics graphics = Graphics.FromImage(bmp); gw.bgnd.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(foundings[fix].backgroundColor.R, foundings[fix].backgroundColor.G, foundings[fix].backgroundColor.B)); graphics.Clear(Color.Transparent); foreach (var p in board.points) { graphics.FillRectangle(p.Color == 1 ? redBrush : blackBrush, new Rectangle(spoint + p.X * bsize, spoint - (p.Y + 1) * bsize, bsize, bsize)); // 1 graphics.FillRectangle(p.Color == 1 ? redBrush : blackBrush, new Rectangle(spoint - (p.Y + 1) * bsize, spoint - (p.X + 1) * bsize, bsize, bsize)); // 2 graphics.FillRectangle(p.Color == 1 ? redBrush : blackBrush, new Rectangle(spoint - (p.X + 1) * bsize, spoint + (p.Y) * bsize, bsize, bsize)); // 3 graphics.FillRectangle(p.Color == 1 ? redBrush : blackBrush, new Rectangle(spoint + (p.Y) * bsize, spoint + p.X * bsize, bsize, bsize)); // 4 } var res = bmp.Clone(); for (int i = 0; i < 32; i++) { graphics.FillRectangle(grayBrush, new Rectangle(spoint + bsize * i, 0, 1, imageSize)); graphics.FillRectangle(grayBrush, new Rectangle(0, spoint + bsize * i, imageSize, 1)); graphics.FillRectangle(grayBrush, new Rectangle(spoint - bsize * i, 0, 1, imageSize)); graphics.FillRectangle(grayBrush, new Rectangle(0, spoint - bsize * i, imageSize, 1)); graphics.FillRectangle(grayBrush, new Rectangle(spoint - bsize * i, 0, 1, imageSize)); graphics.FillRectangle(grayBrush, new Rectangle(0, spoint + bsize * i, imageSize, 1)); graphics.FillRectangle(grayBrush, new Rectangle(spoint + bsize * i, 0, 1, imageSize)); graphics.FillRectangle(grayBrush, new Rectangle(0, spoint - bsize * i, imageSize, 1)); } //panel1.BackgroundImage = bmp; System.Drawing.Image orig = Bitmap.FromFile("ornaments/" + foundings[fix].imageFile); System.Drawing.Image shirt = Bitmap.FromFile("shirts/" + shirts[six].imageFile); Graphics gp = Graphics.FromImage(orig); Graphics gs = Graphics.FromImage(shirt); for (int i = 0; i < foundings[fix].ornamentPlaces.Count; i++) { Bitmap resized = new Bitmap(((Bitmap)res), new System.Drawing.Size((int)(foundings[fix].ornamentPlaces[i].width / Math.Sqrt(2)), (int)(foundings[fix].ornamentPlaces[i].width / Math.Sqrt(2)))); resized = RotateImg(resized, foundings[fix].ornamentPlaces[i].rotate, Color.Transparent); gp.DrawImage(resized, new System.Drawing.Point((int)foundings[fix].ornamentPlaces[0].centerPos.X - resized.Width / 2, (int)foundings[fix].ornamentPlaces[0].centerPos.Y - resized.Height / 2)); } for (int i = 0; i < shirts[six].regions.Count; i++) { float scale = shirts[six].regions[i].width * 1.0f / orig.Width; Bitmap resized = new Bitmap(orig, new System.Drawing.Size((int)(orig.Width * scale), (int)(orig.Height * scale))); TextureBrush tBrush = new TextureBrush(resized); tBrush.RotateTransform(shirts[six].regions[i].rotate); var r = new GraphicsPath(); gs.FillPolygon(tBrush, shirts[six].regions[i].dots.ToArray(), FillMode.Winding); } gw.gen.Source = GetImageStream(bmp); gw.orn.Source = GetImageStream(orig); gw.shirt.Source = GetImageStream(shirt); nameBox.Text = text.ToUpper(); bmp.Save(text + ".bmp"); orig.Save(text + fix + ".bmp"); gw.Show(); //pictureBox1.Image = orig; //pictureBox2.Image = shirt; }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (l1.Count > 0) { s = l1[gen]; } Graphics g = e.Graphics; g.DrawImage(fon2, new Rectangle(0, 0, Convert.ToInt32(rs * koef), Convert.ToInt32(rv * koef))); //рисуем картинку на Bitmap play1 = new Bitmap(Image.FromFile(puthUr + "\\" + s)); //добавила объекты vo = Convert.ToInt32(play1.Height * koef) + vusota; so = Convert.ToInt32(play1.Width * koef) + shirina; Bitmap play2 = new Bitmap(Image.FromFile(puthUr + "\\" + l1[gen]), so, vo); //добавила объекты int sdvigvr = 0; if (so > vo) { sdvigvr = so; } else { sdvigvr = vo; } TextureBrush tb = new TextureBrush(play2, System.Drawing.Drawing2D.WrapMode.Clamp); //создаем текстурную кисть tb.TranslateTransform(so / 2, vo / 2); //сдвиг объектов tb.RotateTransform(gr, System.Drawing.Drawing2D.MatrixOrder.Prepend); //поворот tb.TranslateTransform(-so / 2, -vo / 2); //сдвиг объектов Bitmap p3 = new Bitmap(sdvigvr, sdvigvr); //картинка для осуществления поворота Graphics g2 = Graphics.FromImage(p3); //формирование графики для поворота pictureBox3.Image = p3; //привязка графики к полю для рисования Bitmap r = new Bitmap(fon2); pictureBox4.Image = r; g3 = Graphics.FromImage(r); //формирование графики для поворота g2.FillRectangle(tb, 0, 0, sdvigvr, sdvigvr); //прорисовка поворота Bitmap p1 = new Bitmap(pictureBox3.Image); //создание программы той картинки if (centrx >= xt - 20 && centry >= yt - 20 && centrx <= xt + 20 && centry <= yt + 20) { g.DrawImage(p1, new PointF(centrx - so / 2, centry - vo / 2));//загружаем объект который падает g3.DrawImage(p1, new PointF(centrx - so / 2, centry - vo / 2)); } else { g.DrawImage(p1, new PointF(x + sdvig, y + sdvig));//загружаем объект который падает g3.DrawImage(p1, new PointF(x + sdvig, y + sdvig)); } }