public RotateTransform ( float angle ) : void | ||
angle | float | |
return | void |
public static Bitmap Rotate1(Bitmap bmp, float angle) { TextureBrush MyBrush = new TextureBrush(bmp); double h = Math.Sin(angle) * (bmp.Height / 2) + Math.Sin(90 - angle) * (bmp.Height / 2); MyBrush.RotateTransform(angle); Bitmap dst = new Bitmap((int)(h * 2), (int)(h * 2)); Graphics g = Graphics.FromImage(dst); //g.DrawImageUnscaled(MyBrush.Image, 0, 0, bmp.Width, bmp.Height); //g.FillRectangle(MyBrush,0, 0, (int)(h * 2), (int)(h*2)); g.SmoothingMode = SmoothingMode.HighQuality; g.TranslateTransform(0,0); g.RotateTransform(angle); g.DrawImage(bmp, 0, 0); g.Dispose(); return dst; }
void CreatePatternBrush(float pixelSize) { // Determine adjusted pixel size of the brush to create. const float MAX_PATTERN_SIZE = 80; const float MIN_PATTERN_SIZE = 10; if (pixelSize < patternWidth / MAX_PATTERN_SIZE) pixelSize = patternWidth / MAX_PATTERN_SIZE; if (pixelSize < patternHeight / MAX_PATTERN_SIZE) pixelSize = patternHeight / MAX_PATTERN_SIZE; if (pixelSize > patternWidth / MIN_PATTERN_SIZE) pixelSize = patternWidth / MIN_PATTERN_SIZE; if (pixelSize > patternHeight / MIN_PATTERN_SIZE) pixelSize = patternHeight / MIN_PATTERN_SIZE; if (patternBrushes != null && Math.Abs(pixelSize - pixelSizeCached) / pixelSize < 0.01) return; // the pattern brush is already OK size. // Get size of bitmap to create with the image of the pattern. float width = (float) Math.Round(patternWidth / pixelSize); float height = (float) Math.Round(patternHeight / pixelSize); // Create dictionary to hold brushes for each color. patternBrushes = new Dictionary<SymColor, Brush>(2); pixelSizeCached = pixelSize; RenderOptions renderOpts = new RenderOptions(); renderOpts.minResolution = pixelSize; renderOpts.usePatternBitmaps = false; foreach (SymColor color in map.colors) { if (!patternGlyph.HasColor(color)) continue; // Create a new bitmap and fill it transparent. Bitmap bitmap = new Bitmap((int) width, (int) (offsetRows ? height * 2 : height)); Graphics g = Graphics.FromImage(bitmap); g.CompositingMode = CompositingMode.SourceCopy; g.SmoothingMode = SmoothingMode.HighQuality; g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, bitmap.Width, bitmap.Height); // Set the center of the bitmap to 0,0, and scale to mm (each pixel is 0.01 mm). g.TranslateTransform(width / 2.0F, height / 2.0F); g.ScaleTransform(width / patternWidth, height / patternHeight); // Draw the pattern into the bitmap. GraphicsTarget grTarget = new GraphicsTarget(g); patternGlyph.Draw(grTarget, new PointF(0F, 0F), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts); if (offsetRows) { patternGlyph.Draw(grTarget, new PointF(patternWidth / 2, patternHeight), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts); patternGlyph.Draw(grTarget, new PointF(-patternWidth / 2, patternHeight), -patternAngle, GraphicsUtil.IdentityMatrix, null, color, renderOpts); } // Create a TextureBrush on the bitmap. TextureBrush brush = new TextureBrush(bitmap); // Scale and the texture brush. brush.RotateTransform(patternAngle); brush.ScaleTransform(patternWidth / width, patternHeight / height); brush.TranslateTransform(-width / 2.0F, -height / 2.0F); // Dispose of the graphics. g.Dispose(); // Add it to the collection of brushes. patternBrushes.Add(color, brush); } }
private void CreateCheckCodeImage(string checkCode) { if (checkCode == null || checkCode.Trim() == String.Empty) return; System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 40.5)), 44); Graphics g = Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); Color color = colors[random.Next(colors.Length)]; //清空图片背景色 g.Clear(Color.Transparent); //画图片的背景噪音线 //for (int i = 0; i < 2; i++) //{ // int x1 = random.Next(image.Width); // int x2 = random.Next(image.Width); // int y1 = random.Next(image.Height); // int y2 = random.Next(image.Height); // g.DrawArc(new Pen(Color.Blue, 2), image.Width / 2, 0, image.Width, image.Height, 88, 1000); // //g.DrawLine(new Pen(Color.Blue), image.Width / 4, image.Height / 4, x2, y2); //} for (int i = 0; i < 2; i++) { int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawArc(new Pen(color, 2), -x1, -y1, image.Width * 2, image.Height, 45, 100); } Font font = new System.Drawing.Font("Arial", 24, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), color, color, 1.2f, true); g.DrawString(checkCode, font, brush, 2, 2); int angle = 40;// random.Next(80) - 40; double sin = Math.Sin(Math.PI * angle / 180); double cos = Math.Cos(Math.PI * angle / 180); double tan = Math.Atan(Math.PI * angle / 180); int px = 0;// (int)(sin * 20d);// angle / 2; int py = 0; //(int)(sin * 22d);// 2 - angle / 3; if (angle > 0) { px = (int)(sin * 20d);// angle / 2; py = (int)(-sin * image.Width); } else { //px = py = (int)(-sin * 22d); } //g.TranslateTransform(px, 0); //g.RotateTransform(angle); //g.DrawString(checkCode[0].ToString(), font, brush, image.Width / 8, image.Width / 8*2/image.Width*py); TextureBrush MyBrush = new TextureBrush(image); MyBrush.RotateTransform(30); //g.TranslateTransform(px, py * 3); //g.DrawString(checkCode[1].ToString(), font, brush, 15, 0); //g.RotateTransform(-angle); //angle = random.Next(80) - 40; //px = 20 + angle / 2; //py = angle / 3; //g.RotateTransform(angle); //g.DrawString(checkCode[1].ToString(), font, brush, px, py); //g.DrawString(checkCode[0].ToString(), font, brush, 2, 2); //g.RotateTransform(-30f); //g.DrawString(checkCode[1].ToString(), font, brush, 18+6, 0); //g.RotateTransform(-60f); //g.DrawString(checkCode[1].ToString(), font, brush, 9, 27); //g.TranslateTransform(32, 0); //g.RotateTransform(120F); //g.DrawString(checkCode[1].ToString(), font, brush, 2, 2); //g1.DrawImage(image,61,44, //画图片的前景噪音点 //for (int i = 0; i < 25; i++) //{ // int x = random.Next(image.Width); // int y = random.Next(image.Height); // image.SetPixel(x, y, Color.FromArgb(random.Next())); //} //画图片的边框线 //g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); //image.Save(string.Format("1.bmp")); //image = KiRotate(image, -45f, Color.Transparent); //Bitmap dst = new Bitmap((int)image.Width*2, (int)image.Height); //g = Graphics.FromImage(dst); //g.DrawImage(image, 0, 0); //g.DrawImage(image, image.Width, 0); image.Save("c:\\1.jpg", System.Drawing.Imaging.ImageFormat.Png); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); Response.ClearContent(); Response.ContentType = "image/Gif"; Response.BinaryWrite(ms.ToArray()); } finally { g.Dispose(); image.Dispose(); } }
public void RotateTransform_InvalidOrder () { TextureBrush t = new TextureBrush (image); t.RotateTransform (720, (MatrixOrder) Int32.MinValue); }
/// <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 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"); }
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"); }
private void drawOuterFrame(Point point1,Point point2,Point point3,Point point4,Point point5,Point point6,Point point7,Point point8,Point point9,Point point10,Point point11,Point point12) { Point[] BottomcurvePoints = { point1, point4, point3, point2 }; Point[] RightcurvePoints = { point4, point6, point5, point3 }; Point[] TopcurvePoints = { point6, point8, point7, point5 }; Point[] LeftcurvePoints = { point8, point1, point2, point7 }; this.Woodcutter.DrawPolygon(this.FramPen, TopcurvePoints); this.Woodcutter.DrawPolygon(this.FramPen, RightcurvePoints); this.Woodcutter.DrawPolygon(this.FramPen, LeftcurvePoints); this.Woodcutter.DrawPolygon(this.FramPen, BottomcurvePoints); TextureBrush FrameLeft=new TextureBrush(this.FrameImage); this.Woodcutter.FillPolygon(FrameLeft, LeftcurvePoints); TextureBrush FrameTop = new TextureBrush(this.FrameImage); FrameTop.TranslateTransform(0, 0); FrameTop.RotateTransform(90); this.Woodcutter.FillPolygon(FrameTop, BottomcurvePoints); TextureBrush FrameRight = new TextureBrush(this.FrameImage); FrameRight.TranslateTransform(this.FrameWidth - this.FrameImageWidth, 0); FrameRight.RotateTransform(180); this.Woodcutter.FillPolygon(FrameRight, RightcurvePoints); TextureBrush FrameBottom = new TextureBrush(this.FrameImage); FrameBottom.TranslateTransform(this.FrameImageWidth,this.FrameHeight); FrameBottom.RotateTransform(270); this.Woodcutter.FillPolygon(FrameBottom, TopcurvePoints); }
private void AcquireBrushes() { if (!BackgroundImage) { _useBrush = new SolidBrush(BackgroundColour); } else { try { //RectangleF framerect = new RectangleF(0, 0, Backgroundframes[CurrentFrame].Width, Backgroundframes[CurrentFrame].Height); TextureBrush tbrush = new TextureBrush(Backgroundframes[_currentFrame]); Debug.Print("issueing translatetransform" + CurrentOffset.ToString()); if (CurrentRotation != 0) { tbrush.RotateTransform((float)CurrentRotation, MatrixOrder.Append); } tbrush.TranslateTransform(CurrentOffset.X, CurrentOffset.Y); _useBrush = tbrush; } catch (OutOfMemoryException em) { //texturebrush error _mustDrawManual=true; _useBrush=null; } } }
private void drawMatFrame(Point point1, Point point2, Point point3, Point point4, Point point5, Point point6, Point point7, Point point8, Point point9, Point point10, Point point11, Point point12) { Point[] BottomcurvePoints = { point2, point3, point10, point9 }; Point[] RightcurvePoints = { point3, point5, point11, point10 }; Point[] TopcurvePoints = { point5, point7, point12, point11 }; Point[] LeftcurvePoints = { point7, point2, point9, point12 }; //Bottom this.Woodcutter.DrawPolygon(this.MatPen, TopcurvePoints); //Left this.Woodcutter.DrawPolygon(this.MatPen, LeftcurvePoints); //Right this.Woodcutter.DrawPolygon(this.MatPen, RightcurvePoints); //Top this.Woodcutter.DrawPolygon(this.MatPen, BottomcurvePoints); TextureBrush Topbrush = new TextureBrush(this.MatImage); Topbrush.TranslateTransform(this.FrameImageWidth,this.FrameImageWidth); TextureBrush Bottombrush = new TextureBrush(this.MatImage); Bottombrush.TranslateTransform(this.FrameImageWidth,this.FrameHeight-this.FrameImageWidth); Bottombrush.RotateTransform(180); this.Woodcutter.FillPolygon(Bottombrush, TopcurvePoints); TextureBrush Rightbrush = new TextureBrush(this.MatImage); Rightbrush.TranslateTransform(this.FrameWidth-this.FrameImageWidth-this.MatImage.Width,this.FrameImageWidth); Rightbrush.RotateTransform(90); this.Woodcutter.FillPolygon(Rightbrush, RightcurvePoints); this.Woodcutter.FillPolygon(Topbrush, BottomcurvePoints); TextureBrush Leftbrush = new TextureBrush(this.MatImage); Leftbrush.TranslateTransform(this.FrameImageWidth, this.FrameImageWidth); Leftbrush.RotateTransform(90); Leftbrush.RotateTransform(180); this.Woodcutter.FillPolygon(Leftbrush, LeftcurvePoints); }
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; } }
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()); }
public static TextureBrush MakePatternBrush(Bitmap bmp, float angle) { TextureBrush tb = new TextureBrush(bmp); tb.RotateTransform(angle); return tb; }
private void button12_Click(object sender, EventArgs e) { Graphics g = this.pictureBox2.CreateGraphics(); float MyAngle = 0;//旋转的角度 while (MyAngle < 90) { TextureBrush MyBrush = new TextureBrush(pictureBox2.Image); this.pictureBox2.Refresh(); MyBrush.RotateTransform(MyAngle); g.FillRectangle(MyBrush, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); MyAngle += 0.5f; System.Threading.Thread.Sleep(50); } }