本文整理匯總了C#中System.Drawing.TextureBrush.RotateTransform方法的典型用法代碼示例。如果您正苦於以下問題:C# TextureBrush.RotateTransform方法的具體用法?C# TextureBrush.RotateTransform怎麽用?C# TextureBrush.RotateTransform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.TextureBrush
的用法示例。
在下文中一共展示了TextureBrush.RotateTransform方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Rotate1
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;
}
示例2: CreatePatternBrush
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);
}
}
示例3: CreateCheckCodeImage
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);
//.........這裏部分代碼省略.........
示例4: RotateTransform_InvalidOrder
public void RotateTransform_InvalidOrder ()
{
TextureBrush t = new TextureBrush (image);
t.RotateTransform (720, (MatrixOrder) Int32.MinValue);
}
示例5: FillPath
/// <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);
}
示例6: ResetTransform
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");
}
示例7: RotateTransform
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");
}
示例8: drawOuterFrame
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);
}
示例9: AcquireBrushes
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;
}
}
}
示例10: drawMatFrame
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);
}
示例11: Redraw
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);
}
//.........這裏部分代碼省略.........
示例12: TextureBush_10
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());
}
示例13: MakePatternBrush
public static TextureBrush MakePatternBrush(Bitmap bmp, float angle)
{
TextureBrush tb = new TextureBrush(bmp);
tb.RotateTransform(angle);
return tb;
}
示例14: button12_Click
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);
}
}