本文整理汇总了C#中GraphicsPath.AddString方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicsPath.AddString方法的具体用法?C# GraphicsPath.AddString怎么用?C# GraphicsPath.AddString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphicsPath
的用法示例。
在下文中一共展示了GraphicsPath.AddString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResimOlustur
private void ResimOlustur(int genislik, int yukseklik)
{
Bitmap bitmap = new Bitmap(genislik, yukseklik, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0, 0, genislik, yukseklik);
HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
g.FillRectangle(hatchBrush, rect);
SizeF size;
float fontSize = rect.Height + 1;
Font font;
do
{
fontSize--;
font = new Font(System.Drawing.FontFamily.GenericSerif.Name, fontSize, FontStyle.Bold);
size = g.MeasureString(this.text, font);
} while (size.Width > rect.Width);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
GraphicsPath path = new GraphicsPath();
path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
float v = 4F;
PointF[] points =
{
new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
};
Matrix matrix = new Matrix();
matrix.Translate(0F, 0F);
path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
g.FillPath(hatchBrush, path);
int m = Math.Max(rect.Width, rect.Height);
for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
{
int x = this.random.Next(rect.Width);
int y = this.random.Next(rect.Height);
int w = this.random.Next(m / 50);
int h = this.random.Next(m / 50);
g.FillEllipse(hatchBrush, x, y, w, h);
}
font.Dispose();
hatchBrush.Dispose();
g.Dispose();
this.Image = bitmap;
}
示例2: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.CompositingMode = CompositingMode.SourceOver;
GraphicsPath stroke = new GraphicsPath();
stroke.AddString(this.Text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
string tmp = this.Text;
while (stroke.GetBounds().Width > this.Width - 8) {
tmp = tmp.Substring(0, tmp.Length - 1);
stroke = new GraphicsPath();
stroke.AddString(tmp + "...", this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
}
RectangleF bounds = stroke.GetBounds();
Matrix translationMatrix = new Matrix();
if (this.TextAlign == ContentAlignment.TopRight || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.BottomRight) {
translationMatrix.Translate(this.Width - bounds.Width - 8, 0);
} else if (this.TextAlign == ContentAlignment.TopCenter || this.TextAlign == ContentAlignment.MiddleCenter || this.TextAlign == ContentAlignment.BottomCenter) {
translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, 0);
}
if (this.TextAlign == ContentAlignment.MiddleLeft || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.MiddleCenter) {
translationMatrix.Translate(0, (this.Height - bounds.Height - 5) / 2);
} else if (this.TextAlign == ContentAlignment.BottomLeft || this.TextAlign == ContentAlignment.BottomCenter || this.TextAlign == ContentAlignment.BottomRight) {
translationMatrix.Translate(0, (this.Height - bounds.Height - 5));
}
stroke.Transform(translationMatrix);
e.Graphics.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */
e.Graphics.FillPath(Brushes.White, stroke); /* Text */
}
示例3: GenerateImage
// ====================================================================
// Creates the bitmap image.
// ====================================================================
private void GenerateImage()
{
// Create a new 32-bit bitmap image.
Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);
// Create a graphics object for drawing.
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0, 0, this.width, this.height);
// Fill in the background.
HatchBrush hatchBrush = new HatchBrush(HatchStyle.OutlinedDiamond, Color.LightGray, Color.White);
g.FillRectangle(hatchBrush, rect);
// Set up the text font.
SizeF size;
float fontSize = rect.Height + 1;
Font font;
// Adjust the font size until the text fits within the image.
do
{
fontSize--;
font = new Font(this.familyName, fontSize, FontStyle.Strikeout);
size = g.MeasureString(this.text, font);
} while (size.Width > rect.Width);
// Set up the text format.
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
// Create a path using the text and warp it randomly.
GraphicsPath path = new GraphicsPath();
path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
float v = 4F;
PointF[] points =
{
new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
};
Matrix matrix = new Matrix();
matrix.Translate(0F, 0F);
path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
// Draw the text.
hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
g.FillPath(hatchBrush, path);
// Add some random noise.
int m = Math.Max(rect.Width, rect.Height);
for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
{
int x = this.random.Next(rect.Width);
int y = this.random.Next(rect.Height);
int w = this.random.Next(m / 50);
int h = this.random.Next(m / 50);
g.FillEllipse(hatchBrush, x, y, w, h);
}
// Clean up.
font.Dispose();
hatchBrush.Dispose();
g.Dispose();
// Set the image.
this.image = bitmap;
}
示例4: DrawText
public void DrawText(string aText)
{
Graphics g = Graphics.FromImage(result);
int startsize = Height;
Font f = new Font("Verdana", startsize, FontStyle.Bold, GraphicsUnit.Pixel);
do
{
f = new Font("Verdana", startsize, GraphicsUnit.Pixel);
startsize--;
} while ((g.MeasureString(aText, f).Width >= Width) || (g.MeasureString(aText, f).Height >= Height));
SizeF sf = g.MeasureString(aText, f);
int width = Convert.ToInt32(sf.Width);
int height = Convert.ToInt32(sf.Height);
int x = Convert.ToInt32(Math.Abs((double)width - (double)Width) * rnd.NextDouble());
int y = Convert.ToInt32(Math.Abs((double)height - (double)Height) * rnd.NextDouble());
//////// Paths ///
GraphicsPath path = new GraphicsPath(FillMode.Alternate);
FontFamily family = new FontFamily("Verdana");
int fontStyle = (int)(FontStyle.Regular);
float emSize = f.Size;
Point origin = new Point(x, y);
StringFormat format = StringFormat.GenericDefault;
path.AddString(aText, family, fontStyle, emSize, origin, format);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Rectangle rect = new Rectangle(0, 0, Width, Height);
g.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.White, 0f), rect);
g.SmoothingMode = SmoothingMode.HighQuality;
Color noiseCol = Color.FromArgb(100, 120, 180);
Pen p = new Pen(noiseCol);
/* generate random dots in background */
for( int i=0; i<(Width*Height)/3; i++ ) {
g.FillEllipse(Brushes.Blue, rnd.Next(0, Width), rnd.Next(0, Height), 1, 1);
}
/*noise ends here*/
/* generate random lines in background */
for( int i=0; i<(Width*Height)/150; i++ ) {
g.DrawLine(p,rnd.Next(0,Width), rnd.Next(0,Height), rnd.Next(0,Width), rnd.Next(0,Height));
}
Color textColor = Color.FromArgb(20, 40, 100);
g.FillPath(new SolidBrush(textColor), path);
g.Dispose();
}
示例5: GenerateImage
// ====================================================================
// Creates the bitmap image.
// ====================================================================
private void GenerateImage()
{
// Set up the text font.
//SizeF size;
float fontSize = 14;
Font font;
font = new Font(this.familyName, fontSize, FontStyle.Regular);
// Declare a proposed size with dimensions set to the maximum integer value.
Size proposedSize = new Size(int.MaxValue, int.MaxValue);
Bitmap bitmap2 = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics g2 = Graphics.FromImage(bitmap2);
g2.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0, 0, width + 1, (int)height + 1);
// Fill in the background.
g2.FillRectangle(Brushes.White, rect);
// Set up the text format.
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Near;
// Create a path using the text and warp it randomly.
GraphicsPath path = new GraphicsPath();
path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
g2.FillPath(Brushes.Black, path);
// Clean up.
font.Dispose();
g2.Dispose();
// Set the image.
this.image = bitmap2;
}
示例6: GenerateImage
private void GenerateImage()
{
Bitmap bitmap = new Bitmap
(this.width, this.height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0, 0, this.width, this.height);
HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti,
Color.White, Color.White);
g.FillRectangle(hatchBrush, rect);
SizeF size;
float fontSize = rect.Height + 1;
Font font;
do
{
fontSize--;
font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
size = g.MeasureString(this.text, font);
} while (size.Width > rect.Width);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
GraphicsPath path = new GraphicsPath();
//path.AddString(this.text, font.FontFamily, (int) font.Style,
// font.Size, rect, format);
path.AddString(this.text, font.FontFamily, (int)font.Style, 30, rect, format);
//float v = 4F;
//PointF[] points =
// {
// new PointF(this.random.Next(rect.Width) / v, this.random.Next(
// rect.Height) / v),
// new PointF(rect.Width - this.random.Next(rect.Width) / v,
// this.random.Next(rect.Height) / v),
// new PointF(this.random.Next(rect.Width) / v,
// rect.Height - this.random.Next(rect.Height) / v),
// new PointF(rect.Width - this.random.Next(rect.Width) / v,
// rect.Height - this.random.Next(rect.Height) / v)
// };
//Matrix matrix = new Matrix();
//matrix.Translate(0F, 0F);
//path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.CornflowerBlue);
g.FillPath(hatchBrush, path);
//int m = Math.Max(rect.Width, rect.Height);
//for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
//{
// int x = this.random.Next(rect.Width);
// int y = this.random.Next(rect.Height);
// int w = this.random.Next(m / 50);
// int h = this.random.Next(m / 50);
// g.FillEllipse(hatchBrush, x, y, w, h);
//}
font.Dispose();
hatchBrush.Dispose();
g.Dispose();
this.image = bitmap;
}
示例7: TextPath
private GraphicsPath TextPath(string s, Font f, Rectangle r)
{
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Near;
stringFormat.LineAlignment = StringAlignment.Near;
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddString(s, f.FontFamily, (int)f.Style, f.Size, r, stringFormat);
return graphicsPath;
}
示例8: RefreshPath
// Create the corresponding GraphicsPath for the shape, and apply
// it to the control by setting the Region property.
private void RefreshPath()
{
path = new GraphicsPath();
patje = new GraphicsPath();
//switch (shape)
//{
// case ShapeType.PosRectangle:
path.AddRectangle(this.ClientRectangle);
patje.AddString("POS1", new FontFamily("Arial"), (int)FontStyle.Regular, 10, new Point(4, 7), StringFormat.GenericDefault);
// break;
// case ShapeType.Ellipse:
// path.AddEllipse(this.ClientRectangle);
// break;
// case ShapeType.Triangle:
// Point pt1 = new Point(this.Width / 2, 0);
// Point pt2 = new Point(0, this.Height);
// Point pt3 = new Point(this.Width, this.Height);
// path.AddPolygon(new Point[] { pt1, pt2, pt3 });
// break;
//}
this.Region = new Region(path);
}
示例9: updateClock
/*
private void updateClock() {
lblSongTime.Text = timeToString(coolProgressBar1.Value) + " / " + timeToString(coolProgressBar1.Maximum);
lblSongTime.Refresh();
}
*/
private void RenderText(Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.CompositingQuality = CompositingQuality.HighQuality;
g.CompositingMode = CompositingMode.SourceOver;
String text = valueToString(this.Value) + " / " + valueToString(this.Maximum);
GraphicsPath stroke = new GraphicsPath();
stroke.AddString(text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault);
RectangleF bounds = stroke.GetBounds();
/* Align right */
Matrix translationMatrix = new Matrix();
translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, (this.Height - bounds.Height - 5) / 2);
stroke.Transform(translationMatrix);
g.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */
g.FillPath(Brushes.White, stroke); /* Text */
}