本文整理汇总了C#中Font.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Font.Dispose方法的具体用法?C# Font.Dispose怎么用?C# Font.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Font
的用法示例。
在下文中一共展示了Font.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateImage
private void UpdateImage()
{
Image image = new Image(ImageMode.Rgba,new ImageSize(110,100),new ImageColor(0,0,0,0));
Font font = new Font(FontAlias.System,50,FontStyle.Regular);
image.DrawText(playerScore + " - " + aiScore,new ImageColor(255,255,255,255),font,new ImagePosition(0,0));
image.Decode();
var texture = new Texture2D(110,100,false,PixelFormat.Rgba);
if(this.TextureInfo.Texture != null)
this.TextureInfo.Texture.Dispose();
this.TextureInfo.Texture = texture;
texture.SetPixels(0,image.ToBuffer());
font.Dispose();
image.Dispose();
}
示例2: CreateTextureFromText
/// <summary>
/// 文字列からテクスチャ作成
/// </summary>
/// <returns>
/// テクスチャ
/// </returns>
/// <param name='text'>
/// 文字列
/// </param>
/// <param name='font'>
/// フォント
/// </param>
/// <param name='argb'>
/// ARGB
/// </param>
public static Texture2D CreateTextureFromText(string text, Font font, uint argb)
{
int width = font.GetTextWidth(text, 0, text.Length);
int height = font.Metrics.Height;
var image = new Image(ImageMode.Rgba, new ImageSize(width,height),new ImageColor(0,0,0,0));
image.DrawText(text,new ImageColor((int)((argb >> 16) & 0xff),
(int)((argb >> 8) & 0xff),
(int)((argb >> 0) & 0xff),
(int)((argb >> 24) & 0xff)),font,new ImagePosition(0,0));
var texture = new Texture2D(width,height,false, PixelFormat.Rgba);
texture.SetPixels(0, image.ToBuffer());
image.Dispose();
font.Dispose();
return texture;
}
示例3: UpdateImage
public static void UpdateImage(int score)
{
Image image = new Image(ImageMode.Rgba,new ImageSize(960,544),new ImageColor(0,0,0,0));
Font font = new Font(FontAlias.System,20,FontStyle.Regular);
image.DrawText("Your Total Score: " + score,new ImageColor(255,255,255,255),font,new ImagePosition(25,125));
image.Decode();
//var texture = new Texture2D(960,544,false,PixelFormat.Rgba);
//if(textInfo.Texture != null)
//textInfo.Texture.Dispose();
//textInfo.Texture = texture;
//texture.SetPixels(0,image.ToBuffer());
font.Dispose();
image.Dispose();
}
示例4: SetFamilyName
// ====================================================================
// Sets the font used for the image text.
// ====================================================================
private void SetFamilyName(string familyName)
{
// If the named font is not installed, default to a system font.
try
{
Font font = new Font(this.familyName, 12F);
this.familyName = familyName;
font.Dispose();
}
catch (Exception ex)
{
string err = ex.Message;
this.familyName = System.Drawing.FontFamily.GenericSerif.Name;
}
}
示例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: UpdateImage
public static void UpdateImage(string highScores)
{
Image image = new Image(ImageMode.Rgba,new ImageSize(960,544),new ImageColor(0,0,0,0));
Font font = new Font(FontAlias.System,25,FontStyle.Regular);
image.DrawText("High Scores: " + highScores,new ImageColor(255,255,255,255),font,new ImagePosition(25,100));
image.Decode();
var texture = new Texture2D(960,544,false,PixelFormat.Rgba);
if(textInfo.Texture != null)
textInfo.Texture.Dispose();
textInfo.Texture = texture;
texture.SetPixels(0,image.ToBuffer());
font.Dispose();
image.Dispose();
}
示例7: StartWebcam
// Start serving up frames
private void StartWebcam(Webcam cam, ConnectionManager conManager, StreamWriter sw, ImageCodecInfo myImageCodecInfo, EncoderParameters myEncoderParameters)
{
MemoryStream m = new MemoryStream(20000);
Bitmap image = null;
IntPtr ip = IntPtr.Zero;
Font fontOverlay = new Font("Times New Roman", 14, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point);
MotionDetector motionDetector = new MotionDetector();
DateTime lastMotion = DateTime.Now;
int interval = 5;
stopCondition = false;
isRecording = false;
player = new System.Media.SoundPlayer();
motionDetector.MotionLevelCalculation = true;
player.LoadCompleted += new System.ComponentModel.AsyncCompletedEventHandler((obj, arg) => player.PlayLooping());
cam.Start();
while (!stopCondition)
{
try
{
// capture image
ip = cam.GetBitMap();
image = new Bitmap(cam.Width, cam.Height, cam.Stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, ip);
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
motionDetector.ProcessFrame(ref image);
if (motionDetector.MotionLevel >= alarmLevel)
{
if (!isRecording && (DateTime.Now.Second % interval == 0))
conManager.SendMessage("record");
lastMotion = DateTime.Now;
}
else
{
if (DateTime.Now.Subtract(lastMotion).Seconds > interval)
{
if (isRecording)
{
conManager.SendMessage("stop-record");
isRecording = false;
}
if (isAlarming)
{
player.Stop();
isAlarming = false;
}
}
}
// add text that displays date time to the image
image.AddText(fontOverlay, 10, 10, DateTime.Now.ToString());
// save it to jpeg using quality options
image.Save(m, myImageCodecInfo, myEncoderParameters);
// send the jpeg image if server requests it
if (requested)
conManager.SendImage(m);
}
catch (Exception ex)
{
try
{
sw.WriteLine(DateTime.Now.ToString());
sw.WriteLine(ex);
}
catch { }
}
finally
{
// Empty the stream
m.SetLength(0);
// remove the image from memory
if (image != null)
{
image.Dispose();
image = null;
}
if (ip != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(ip);
ip = IntPtr.Zero;
}
}
}
cam.Pause();
player.Stop();
fontOverlay.Dispose();
}
示例8: 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.SmallConfetti, 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.Bold);
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;
}
示例9: DrawText
private Image DrawText(Int32 width, Int32 height, Boolean vertical, String bookfont, String authorfont)
{
//String bookname = VB.Strings.StrConv(bookAndAuthor[0], VB.VbStrConv.SimplifiedChinese, 0);
//String author = VB.Strings.StrConv(bookAndAuthor[1], VB.VbStrConv.SimplifiedChinese, 0);
String bookname = bookAndAuthor[0];
String author = bookAndAuthor[1];
Image img = new Bitmap(width, height);
Graphics drawing = Graphics.FromImage(img);
//paint the background
drawing.Clear(System.Drawing.Color.FromArgb(50, 70, 110));
drawing.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
drawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
drawing.InterpolationMode = InterpolationMode.HighQualityBicubic;
drawing.PixelOffsetMode = PixelOffsetMode.HighQuality;
drawing.CompositingQuality = CompositingQuality.HighQuality;
drawing.CompositingMode = CompositingMode.SourceOver;
System.Drawing.Brush whiteBrush = new SolidBrush(System.Drawing.Color.White);
System.Drawing.Brush orangeBrush = new SolidBrush(System.Drawing.Color.FromArgb(228, 89, 23));
System.Drawing.Brush yellowBrush = new SolidBrush(System.Drawing.Color.Yellow);
System.Drawing.Brush blackBrush = new SolidBrush(System.Drawing.Color.Black);
System.Drawing.Pen whitePen = new System.Drawing.Pen(whiteBrush, width / 1000 * 5);
Rectangle bookNameRec;
Rectangle authorRec1;
Rectangle authorRec2;
if (bookAndAuthor_isChinese)
{
if (!vertical) // 横排书封面
{
drawing.DrawLine(whitePen, new Point(width / 15, 0), new Point(width / 15, height));
drawing.DrawLine(whitePen, new Point(0, height / 10), new Point(width / 15, height / 10));
drawing.DrawLine(whitePen, new Point(0, height / 10 + height / 3), new Point(width / 15, height / 10 + height / 3));
drawing.DrawLine(whitePen, new Point(0, height - height / 10 - height / 3), new Point(width / 15, height - height / 10 - height / 3));
drawing.DrawLine(whitePen, new Point(0, height - height / 10), new Point(width / 15, height - height / 10));
bookNameRec = Rectangle.FromLTRB(width / 2 + width / 10, height / 10, width - width / 10, height / 2 + height / 10);
drawing.FillRectangle(whiteBrush, bookNameRec);
authorRec1 = Rectangle.FromLTRB(width / 2 + width / 10 - width / 20, height / 10, width / 2 + width / 10, height / 2 + height / 10 - height / 40);
drawing.FillRectangle(orangeBrush, authorRec1);
authorRec2 = Rectangle.FromLTRB(width / 2 + width / 10 - width / 20, height / 10 + authorRec1.Height, width / 2 + width / 10, height / 2 + height / 10);
drawing.FillRectangle(orangeBrush, authorRec2);
}
else // 竖排书封面
{
drawing.DrawLine(whitePen, new Point(width - width / 15, 0), new Point(width - width / 15, height));
drawing.DrawLine(whitePen, new Point(width - width / 15, height / 10), new Point(width, height / 10));
drawing.DrawLine(whitePen, new Point(width - width / 15, height / 10 + height / 3), new Point(width, height / 10 + height / 3));
drawing.DrawLine(whitePen, new Point(width - width / 15, height - height / 10 - height / 3), new Point(width, height - height / 10 - height / 3));
drawing.DrawLine(whitePen, new Point(width - width / 15, height - height / 10), new Point(width, height - height / 10));
bookNameRec = Rectangle.FromLTRB(width / 10, height / 10, width / 2 - width / 10, height / 2 + height / 10);
drawing.FillRectangle(whiteBrush, bookNameRec);
authorRec1 = Rectangle.FromLTRB(width / 2 - width / 10, height / 10, width / 2 - width / 10 + width / 20, height / 2 + height / 10 - height / 40);
drawing.FillRectangle(orangeBrush, authorRec1);
authorRec2 = Rectangle.FromLTRB(width / 2 - width / 10, height / 10 + authorRec1.Height, width / 2 - width / 10 + width / 20, height / 2 + height / 10);
drawing.FillRectangle(orangeBrush, authorRec2);
}
StringFormat bookDrawFormat = new StringFormat();
bookDrawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
//bookDrawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
bookDrawFormat.Alignment = StringAlignment.Center;
bookDrawFormat.LineAlignment = StringAlignment.Center;
bookname = ToSBC(bookname);
Tuple<String, Int32> settings = setTitleFontSize(bookname.Length, bookNameRec.Width, bookname, vertical);
//Font bookFont = new Font(privateFontFamilies[1], settings.Item2, FontStyle.Bold);
//Font bookFont = new Font(bookfont, settings.Item2 * DPI.Item2 / 96f, FontStyle.Bold, GraphicsUnit.Pixel);
Font bookFont = new Font(bookfont, settings.Item2 * 96f / DPI.Item2, FontStyle.Bold);
drawing.DrawString(settings.Item1, bookFont, blackBrush, bookNameRec, bookDrawFormat);
StringFormat authorDrawFormat = new StringFormat();
authorDrawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
//authorDrawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
authorDrawFormat.Alignment = StringAlignment.Far;
authorDrawFormat.LineAlignment = StringAlignment.Center;
author = ToSBC(author);
//Font authorFont = new Font(privateFontFamilies[0], authorRec1.Width / 2, FontStyle.Bold);
//Font authorFont = new Font(authorfont, authorRec1.Width / 2 * DPI.Item2 / 96, FontStyle.Bold, GraphicsUnit.Pixel);
Font authorFont = new Font(authorfont, authorRec1.Width / 2 * 96f / DPI.Item2, FontStyle.Bold);
drawing.DrawString(author + " ◆ 著", authorFont, whiteBrush, authorRec1, authorDrawFormat);
drawing.DrawString(" ◆ 著", authorFont, yellowBrush, authorRec1, authorDrawFormat);
drawing.DrawString("著", authorFont, whiteBrush, authorRec1, authorDrawFormat);
bookFont.Dispose();
authorFont.Dispose();
bookDrawFormat.Dispose();
authorDrawFormat.Dispose();
}
else
{
bookNameRec = Rectangle.FromLTRB(width / 15, height / 15, width - width / 15, height - height / 3);
//drawing.FillRectangle(blackBrush, bookNameRec);
authorRec1 = Rectangle.FromLTRB(width / 15, height - height / 3, width - width / 15, height - height / 15);
//drawing.FillRectangle(yellowBrush, authorRec1);
//.........这里部分代码省略.........
示例10: DrawNotePic
private Image DrawNotePic(Int32 width, Int32 height, String word, String bodyfont)
{
Bitmap img = new Bitmap(width, height);
Graphics drawing = Graphics.FromImage(img);
//paint the background
drawing.Clear(System.Drawing.Color.Transparent);
drawing.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
drawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
Rectangle bound = new Rectangle(0, 0, width-1, height-1);
System.Drawing.Brush brownBrush = new SolidBrush(System.Drawing.Color.FromArgb(165, 70, 15));
drawing.FillEllipse(brownBrush, bound);
// Draw word overlay
Bitmap overLay = new Bitmap(width, height);
Graphics drawingOverLay = Graphics.FromImage(overLay);
drawingOverLay.Clear(System.Drawing.Color.Black);
drawingOverLay.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
drawingOverLay.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
drawingOverLay.InterpolationMode = InterpolationMode.HighQualityBicubic;
drawingOverLay.PixelOffsetMode = PixelOffsetMode.HighQuality;
drawingOverLay.CompositingQuality = CompositingQuality.HighQuality;
drawingOverLay.CompositingMode = CompositingMode.SourceOver;
System.Drawing.Brush transparentBrush = new SolidBrush(System.Drawing.Color.White);
StringFormat noteDrawFormat = new StringFormat();
noteDrawFormat.Alignment = StringAlignment.Center;
/*noteDrawFormat.LineAlignment = StringAlignment.Center;
noteDrawFormat.FormatFlags = StringFormatFlags.DirectionVertical;*/
Font noteFont = new Font(bodyfont, 1, FontStyle.Regular);
/*TextFormatFlags flags = TextFormatFlags.NoPadding;
TextRenderer.DrawText(drawingOverLay, word, noteFont, new Point(0, 0), System.Drawing.Color.White, flags);*/
//TextRenderer.DrawText(drawingOverLay, word, noteFont, new Point(0, 0), System.Drawing.Color.FromArgb(165, 70, 15), System.Drawing.Color.White, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter);
drawingOverLay.DrawString(word, scaleFont(drawing, word, noteFont, bound, noteDrawFormat), transparentBrush, bound, noteDrawFormat);
//drawingOverLay.Save();
ApplyAlphaMask(img, overLay);
overLay.Dispose();
drawingOverLay.Dispose();
brownBrush.Dispose();
noteFont.Dispose();
noteDrawFormat.Dispose();
drawing.Save();
drawing.Dispose();
return img;
}
示例11: Initialize
/// <summary>
/// </summary>
/// <param name="font">The font to use to render characters. Note that FontMap disposes of this Font object.</param>
/// <param name="charset">A string containing all the characters you will ever need when drawing text with this FontMap.</param>
/// <param name="fontmap_width">The internal with used by the texture (height is adjusted automatically).</param>
public void Initialize( Font font, string charset, int fontmap_width = 512 )
{
CharSet = new Dictionary< char, CharData >();
CharPixelHeight = font.Metrics.Height;
Image image = null;
Vector2i totalsize = new Vector2i( 0, 0 );
for ( int k=0; k < 2; ++k )
{
Vector2i turtle = new Vector2i( 0, 0 ); // turtle is in Sce.PlayStation.Core.Imaging.Font's coordinate system
int max_height = 0;
for ( int i=0; i < charset.Length; ++i )
{
if ( CharSet.ContainsKey( charset[i] ) )
continue; // this character is already in the map
Vector2i char_size = new Vector2i(
font.GetTextWidth( charset[i].ToString(), 0, 1 ),
font.Metrics.Height
);
max_height = Common.Max( max_height, char_size.Y );
if ( turtle.X + char_size.X > fontmap_width )
{
// hit the right side, go to next line
turtle.X = 0;
turtle.Y += max_height; // Sce.PlayStation.Core.Imaging.Font's coordinate system: top is 0, so we += to move down
max_height = 0;
// make sure we are noit going to newline forever due to lack of fontmap_width
Common.Assert( char_size.Y <= fontmap_width );
}
if ( k > 0 )
{
// that starts from top left
image.DrawText( charset[i].ToString(), new ImageColor(255,255,255,255), font
, new ImagePosition( turtle.X, turtle.Y ) );
var uv = new Bounds2( turtle.Vector2() / totalsize.Vector2()
, ( turtle + char_size ).Vector2() / totalsize.Vector2() );
// now fix the UV to be in GameEngine2D's UV coordinate system, where 0,0 is bottom left
uv = uv.OutrageousYVCoordFlip().OutrageousYTopBottomSwap();
CharSet.Add( charset[i], new CharData(){ UV = uv, PixelSize = char_size.Vector2()} );
}
turtle.X += char_size.X;
if ( k == 0 )
{
totalsize.X = Common.Max( totalsize.X, turtle.X );
totalsize.Y = Common.Max( totalsize.Y, turtle.Y + max_height );
}
}
if ( k == 0 )
{
// System.Console.WriteLine( "FontMap.Initialize: totalsize " + totalsize );
image = new Image( ImageMode.A, new ImageSize( totalsize.X, totalsize.Y ), new ImageColor(0,0,0,0) );
CharSet.Clear(); // we want to go through the same add logic on second pass, so clear
}
}
Texture = new Texture2D( image.Size.Width, image.Size.Height, false, PixelFormat.Luminance );
Texture.SetPixels( 0, image.ToBuffer() );
// image.Export("uh?","hey.png");
image.Dispose();
{
// cache ascii entries so we can skip TryGetValue logic for those
m_ascii_char_data = new CharData[ AsciiCharSet.Length ];
m_ascii_char_data_valid = new bool[ AsciiCharSet.Length ];
for ( int i=0; i < AsciiCharSet.Length; ++i )
{
CharData cdata;
m_ascii_char_data_valid[i] = CharSet.TryGetValue( AsciiCharSet[i], out cdata );
m_ascii_char_data[i] = cdata;
}
}
// dispose of the font by default
font.Dispose();
}