本文整理汇总了C#中System.Drawing.Font.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Font.Dispose方法的具体用法?C# Font.Dispose怎么用?C# Font.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Font
的用法示例。
在下文中一共展示了Font.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Operation
/// <summary>
/// 主要作業方法
/// </summary>
public Image Operation()
{
Graphics g = Graphics.FromImage(image);
_mask_pos_x = (image.Width / 2) + _Xoffset;
SizeF steSize = new SizeF();
for (int i = _FontMaxSize; i >= _FontMinSize; i--)
{
using (Font testFont = new Font(_FontFamily, i, FontStyle.Bold))
{
steSize = g.MeasureString(_text, testFont);
if ((ushort)steSize.Width < (ushort)_Width || i == _FontMinSize)
{
using (SolidBrush semiTransBrush = new SolidBrush(_fontcolor))
{
StringFormat StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Center;
g.DrawString(_text, testFont, semiTransBrush, new PointF(_mask_pos_x, _mask_pos_y), StrFormat);
semiTransBrush.Dispose();
}
testFont.Dispose();
break;
}
}
}
return image;
}
示例2: Operation
/// <summary>
/// 主要作業方法
/// </summary>
public Image Operation()
{
Graphics g = Graphics.FromImage(image);
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
StringFormat strFormat = new StringFormat();
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
using (SolidBrush SB = new SolidBrush(_fontcolor))
{
using (Font str_Font = new Font(_FontFamily, _fontsize, FontStyle.Bold))
{
g.SmoothingMode = SmoothingMode.HighQuality;
SizeF labelSize = g.MeasureString(_text, new Font(_FontFamily, _fontsize, FontStyle.Bold));
//g.TranslateTransform(0, labelSize.Width);
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.RotateTransform(_degree);
g.DrawString(_text, str_Font, new SolidBrush(_fontcolor), _mask_pos_x, _mask_pos_y);
str_Font.Dispose();
}
SB.Dispose();
}
return image;
}
示例3: AddCopyright
public Bitmap AddCopyright(string file)
{
string msg = DateTime.Now.ToShortDateString();
Bitmap bmp = new Bitmap(file);
Graphics g = Graphics.FromImage(bmp);
StringFormat strFmt = new StringFormat();
strFmt.Alignment = StringAlignment.Center;
SolidBrush btmForeColor = new SolidBrush(Color.White);
SolidBrush btnBackColor = new SolidBrush(Color.Transparent);
Font btmFont = new Font("Verdana", 7);
SizeF textSize = new SizeF();
textSize = g.MeasureString(msg, btmFont);
float x = ((float)bmp.Width - textSize.Width - 3);
float y = ((float)bmp.Height - textSize.Height - 3);
float w = ((float)x + textSize.Width);
float h = ((float)y + textSize.Height);
RectangleF textArea = new RectangleF(x, y, w, h);
g.FillRectangle(btnBackColor, textArea);
g.DrawString(msg, btmFont, btmForeColor, textArea);
btmForeColor.Dispose();
btnBackColor.Dispose();
btmFont.Dispose();
g.Dispose();
return bmp;
}
示例4: Draw
public override void Draw(Graphics g, int target)
{
Image head = PicLoader.Read("NPC", string.Format("{0}.PNG", Figue));
int ty = Y + 50;
int ty2 = ty;
if (target == Id)
{
g.DrawImage(head, X - 5, ty - 5, Width*5/4, Width * 5 / 4);
ty2 -= 2;
}
else
{
g.DrawImage(head, X, ty, Width, Width);
}
head.Dispose();
Font font = new Font("΢ÈíÑźÚ", 12*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
g.DrawString(Name, font, Brushes.Black, X + 3, Y + Height + 30);
g.DrawString(Name, font, Brushes.White, X, Y + Height + 27);
font.Dispose();
if (taskFinishs.Count > 0)
{
Image img = PicLoader.Read("System", "MarkTaskEnd.PNG");
g.DrawImage(img, X + 15, ty2 - 35, 21, 30);
img.Dispose();
}
else if (taskAvails.Count > 0)
{
Image img = PicLoader.Read("System", "MarkTaskBegin.PNG");
g.DrawImage(img, X + 15, ty2 - 35, 24, 30);
img.Dispose();
}
}
示例5: monthCalendar1_DayRender
private void monthCalendar1_DayRender(object sender, Pabo.Calendar.DayRenderEventArgs e)
{
Brush bgBrush = new SolidBrush(Color.White);
Brush dateBrush = new SolidBrush(Color.Black);
Font dateFont = new Font("Microsoft Sans Serif",(float)8.25);
StringFormat dateAlign = new StringFormat();
dateAlign.Alignment = StringAlignment.Far;
dateAlign.LineAlignment = StringAlignment.Near;
Rectangle rect = new Rectangle(0,0,e.Width,e.Height);
// Set OwnerDraw = true to override built in formatting...
e.OwnerDraw = true;
// ...then Draw the appearance of the date
e.Graphics.FillRectangle(bgBrush,rect);
e.Graphics.DrawString(e.Date.Day.ToString(),
dateFont,dateBrush,rect,dateAlign);
// Clean up
bgBrush.Dispose();
dateBrush.Dispose();
dateAlign.Dispose();
dateFont.Dispose();
}
示例6: Draw
public override void Draw(Graphics g)
{
if (nid > 0)
{
int itemCount = UserProfile.Profile.InfoBag.GetItemCount(nid);
bool isEnough = itemCount >= need;
g.DrawImage(DataType.Items.HItemBook.GetHItemImage(nid), x, y, width, height);
if (IsIn && isEnough)
{
g.DrawImage(DataType.Items.HItemBook.GetHItemImage(nid), x+3, y+3, width-6, height-6);
}
if (!isEnough)
{//灰色遮罩
Brush brush = new SolidBrush(Color.FromArgb(120, Color.Black));
g.FillRectangle(brush, x, y, width, height);
brush.Dispose();
}
Font fontsong = new Font("宋体", 7*1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
g.DrawString(string.Format("{0}/{1}", need, itemCount), fontsong, isEnough ? Brushes.White : Brushes.Red, x + 1, y + 18);
fontsong.Dispose();
}
foreach (IRegionDecorator decorator in decorators)
{
decorator.Draw(g, x, y, width, height);
}
}
示例7: Draw
public void Draw(Graphics g, bool enable)
{
Image back = PicLoader.Read("System", "ItemGrid.JPG");
g.DrawImage(back, x+3, y+3, 32, 32);
back.Dispose();
if (itemPos >= 0)
{
Font font = new Font("Aril", 11*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
if (enable)
{
g.DrawImage(HItemBook.GetHItemImage(UserProfile.InfoBag.Items[itemPos].Type), x + 3, y + 3, 32, 32);
}
else
{
Rectangle ret = new Rectangle(x + 3, y + 3, 32, 32);
g.DrawImage(HItemBook.GetHItemImage(UserProfile.InfoBag.Items[itemPos].Type), ret, 0, 0, 64, 64, GraphicsUnit.Pixel, HSImageAttributes.ToGray);
}
g.DrawString(UserProfile.InfoBag.Items[itemPos].Value.ToString(), font, Brushes.Black, x + 4, y + 4);
g.DrawString(UserProfile.InfoBag.Items[itemPos].Value.ToString(), font, Brushes.White, x + 3, y + 3);
if (percent>1)
{
Brush brush = new SolidBrush(Color.FromArgb(200, Color.Black));
g.FillRectangle(brush, x, y, 35, 35*percent/100);
brush.Dispose();
}
font.Dispose();
}
}
示例8: PaintValue
public override void PaintValue(PaintValueEventArgs e)
{
var ts = (TextStyle) e.Value;
using (var b = new SolidBrush(ts.BackColor))
{
e.Graphics.FillRectangle(b, e.Bounds);
}
FontStyle fs = FontStyle.Regular;
if (ts.Bold)
fs |= FontStyle.Bold;
if (ts.Italic)
fs |= FontStyle.Italic;
if (ts.Underline)
fs |= FontStyle.Underline;
var f = new Font("arial", 8f, fs);
using (var b = new SolidBrush(ts.ForeColor))
{
e.Graphics.DrawString("abc", f, b, e.Bounds);
}
f.Dispose();
}
示例9: HatchBrushes_Paint
private void HatchBrushes_Paint(object sender, PaintEventArgs e)
{
int y = 20;
int x = 20;
Font font = new Font("Tahoma", 8);
// Enumerate over all the styles.
foreach (HatchStyle brushStyle in System.Enum.GetValues(typeof(HatchStyle)))
{
HatchBrush myBrush = new HatchBrush(brushStyle, Color.Blue, Color.LightYellow);
// Fill a rectangle with the brush.
e.Graphics.FillRectangle(myBrush, x, y, 40, 20);
// Display the brush name.
e.Graphics.DrawString(brushStyle.ToString(), font,
Brushes.Black, 50 + x, y + 5);
y += 30;
if ((y + 30) > this.ClientSize.Height)
{
y = 20;
x += 180;
}
myBrush.Dispose();
}
font.Dispose();
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Bitmap objBMP = new System.Drawing.Bitmap(60, 20);
Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
objGraphics.Clear(Color.Green);
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
//' Configure font to use for text
Font objFont = new Font("Arial", 8, FontStyle.Bold);
string randomStr = "";
int[] myIntArray = new int[5];
int x;
//That is to create the random # and add it to our string
Random autoRand = new Random();
for (x = 0; x < 5; x++)
{
myIntArray[x] = System.Convert.ToInt32(autoRand.Next(0, 9));
randomStr += (myIntArray[x].ToString());
}
//This is to add the string to session cookie, to be compared later
Session.Add("Captcha", randomStr);
//' Write out the text
objGraphics.DrawString(randomStr, objFont, Brushes.White, 3, 3);
//' Set the content type and return the image
Response.ContentType = "image/GIF";
objBMP.Save(Response.OutputStream, ImageFormat.Gif);
objFont.Dispose();
objGraphics.Dispose();
objBMP.Dispose();
}
示例11: MessageBoxEx_Paint
private void MessageBoxEx_Paint(object sender, PaintEventArgs e)
{
if (img != null)
{
e.Graphics.DrawImage(img, 38, 32, 100, 100);
var deck = UserProfile.InfoCard.Decks[selectPage];
for (int i = 0; i < deck.CardIds.Length; i++)
{
int x = i%6;
int y = i/6;
var cardId = deck.CardIds[i];
e.Graphics.DrawImage(CardAssistant.GetCardImage(cardId,100,100),x*20+150,y*20+35,20,20);
var cardJob = CardConfigManager.GetCardConfig(cardId).JobId;
if (cardJob > 0 && cardJob != UserProfile.InfoBasic.Job)
{
var brush = new SolidBrush(Color.FromArgb(150, Color.Red));
e.Graphics.FillRectangle(brush, x * 20 + 150, y * 20 + 35, 20, 20);
brush.Dispose();
e.Graphics.DrawRectangle(Pens.Red, x * 20 + 150, y * 20 + 35, 20, 20);
}
}
}
Font font = new Font("宋体", 9*1.33f, FontStyle.Regular, GraphicsUnit.Pixel);
e.Graphics.DrawString(string.Format("地形:{0}", tile == -1 ? "默认" : ConfigDatas.ConfigData.GetTileConfig(tile).Cname), font, Brushes.White, 63, 117);
font.Dispose();
}
示例12: generateBarcode
public Bitmap generateBarcode(string data)
{
Bitmap b = new Bitmap(1, 1);
Font font = new Font("Free 3 of 9", 60, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
Graphics g = Graphics.FromImage(b);
SizeF dSize = g.MeasureString(data, font);
b = new Bitmap(b, dSize.ToSize());
g = Graphics.FromImage(b);
g.Clear(Color.White);
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
g.DrawString(data, font, new SolidBrush(Color.Black), 0, 0);
g.DrawString(data, new Font("Times new Romanow", 9, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point), new SolidBrush(Color.Black), 65, 58);
g.Flush();
font.Dispose();
g.Dispose();
return b;
}
示例13: AddTextToBitmap
/// <summary>Adds a textual string to a bitmap image</summary>
/// <param name="bitmap">The bitmap image to add the text to, or a null reference if a new image is to be created</param>
/// <param name="txt">The text to overlay</param>
/// <param name="fontname">The name of the font to use</param>
/// <param name="fontsize">The size in points of the font</param>
/// <param name="bgcolor">The background color to use (Only relevant if creating a new image)</param>
/// <param name="fcolor">The font color to use</param>
/// <param name="Padding">The padding to use, or alternatively the X,Y inset if overlaying text</param>
public static Bitmap AddTextToBitmap(Bitmap bitmap, string txt, string fontname, int fontsize, Color bgcolor,Color fcolor, Vector2 Padding)
{
bool overlay = true;
SizeF size;
if (bitmap == null)
{
bitmap = new Bitmap(1024, 1024);
overlay = false;
}
using (Graphics graphics = Graphics.FromImage(bitmap))
{
Font font = new Font(fontname, fontsize);
size = graphics.MeasureString(txt, font);
if (!overlay)
{
graphics.FillRectangle(new SolidBrush(bgcolor), 0, 0, size.Width + (int) Padding.X*2,size.Height + (int) Padding.Y*2);
}
graphics.DrawString(txt, font, new SolidBrush(fcolor), (int) Padding.X, (int) Padding.Y);
graphics.Flush();
font.Dispose();
graphics.Dispose();
}
if (!overlay)
{
Rectangle cropArea = new Rectangle(0, 0, (int) size.Width + (int) Padding.X*2, (int) size.Height + (int) Padding.Y*2);
return bitmap.Clone(cropArea, bitmap.PixelFormat);
}
return bitmap;
}
示例14: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
randomStr = "";
Bitmap objBMP = new Bitmap(600, 200);
Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
objGraphics.Clear(Color.OrangeRed);
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
Font objFont = new Font("Arial", 100, FontStyle.Bold);
int x;
Random autoRand = new Random();
for (x = 0; x < 6; x++)
{
randomStr += (char)autoRand.Next(97, 122);
}
objGraphics.RotateTransform(-4);
objGraphics.ScaleTransform(0.8F, 1.5F);
objGraphics.DrawString(randomStr, objFont, Brushes.White,-10,-10);
Response.ContentType = "image/GIF";
objBMP.Save(Response.OutputStream, ImageFormat.Gif);
objFont.Dispose();
objGraphics.Dispose();
objBMP.Dispose();
}
示例15: GerarCaptcha
/// <summary>
/// Gera um Captcha dentro de um PageLoad em um webform vazio.
/// Para usar, Crie um web form com o nome GerarCaptcha.aspx, e no codebehind chame a classe,
/// Helpers.Arquivos.GerarCaptcha(int width, int height), e na pagina ou local onde quer que o captcha aparece,
/// coloque um web server controle do tipo Image e atribua o ImageUrl="~/GerarCaptcha.aspx".
/// EX: <asp:Image id="captchaImage" runat=server ImageUrl="~/GerarCaptcha.aspx" Height="50px" Width="150px" />
/// Para usar o captcha no CodeBehind faca:
/// 'Compare um campo TextBox com a Session["captcha"].ToString();
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public static void GerarCaptcha(int width, int height)
{
//Prepara os componentes de saida para desenho
Bitmap bmp = new Bitmap(width, height);
Graphics graph = Graphics.FromImage(bmp);
//Limpa com cores locas..
graph.Clear(Color.Aquamarine);
graph.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
//gera um random de letras e numeros
string senhaCaptcha = "";
Random rand = new Random();
for (int x = 0; x < 6; x++)
senhaCaptcha += (char)rand.Next(48, 122); //40 = zero 122 = z
//grava na variavel de sessão
HttpContext.Current.Session.Add("captcha", senhaCaptcha);
//desenha na tela
Font fonte = new Font("Calibri", 14, FontStyle.Italic);
graph.DrawString(senhaCaptcha, fonte, Brushes.OliveDrab, 1, 1);
//Manda pro rersponse
HttpContext.Current.Response.ContentType = "image/gif";
bmp.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Gif);
//Dispose
graph.Dispose();
fonte.Dispose();
bmp.Dispose();
}