本文介绍了大纲文本与System.Drawing中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code。有没有一种简单的方法把大纲上我写作文?

  VAR imageEn codeR = EN coder.Quality;
 VAR imageEn coderParameters =新恩coderParameters(1);
 imageEn coderParameters.Param [0] =新恩coderParameter(imageEn codeR,100L); VAR productImage = GetImageFromByteArray(myViewModel.ProductImage.DatabaseFile.FileContents);
 VAR显卡= Graphics.FromImage(productImage); VAR字体=新的字体(濑越脚本,24);
 VAR刷= Brushes.Orange; VAR集装箱=​​新的Rectangle(myViewModel.ContainerX,myViewModel.ContainerY,myViewModel.ContainerWidth,myViewModel.ContainerHeight); VAR的StringFormat =新的StringFormat {对齐= StringAlignment.Center,LineAlignment = StringAlignment.Center}; graphics.DrawString(customizationText,字体,画笔,容器的StringFormat);


解决方案

是的。代替的DrawString的,使用呼叫的顺序如下:


  • (创建一个空的的GraphicsPath

  • (在的GraphicsPath 对象现在重新presents文字的轮廓)

  • (吸入任何你想要的轮廓)

如果你需要使用 GraphicsPath.AddString 一起 Graphics.DrawString ,您需要将字体大小转换,因为 Graphics.DrawString 预计,点大小,而 GraphicsPath.AddString 预计,新兴市场的大小。其换算公式为根本 emSize = g.DpiY *的pointsize / 72

下面是一个code例如:

  //假设g为Graphics对象上要绘制文本
GraphicsPath的P =新的GraphicsPath();
p.AddString(
    我的文本字符串,//文字画
    FontFamily.GenericSansSerif,//或任何其他字体家族
    (INT)FontStyle.Regular,//字体样式(粗体,斜体等)
    g.DpiY * fontSize的/ 72 // EM大小
    新点(0,0),//位置,绘制文本
    新的StringFormat()); //这里设置的选项(如居中对齐)
g.DrawPath(Pens.Black页);
// + g.FillPath如果你想让它充满以及

I have the following code. Is there an easy way to put an outline on the text I am writing?

 var imageEncoder = Encoder.Quality;
 var imageEncoderParameters = new EncoderParameters(1);
 imageEncoderParameters.Param[0] = new EncoderParameter(imageEncoder, 100L);

 var productImage = GetImageFromByteArray(myViewModel.ProductImage.DatabaseFile.FileContents);
 var graphics = Graphics.FromImage(productImage);

 var font = new Font("Segoe Script", 24);
 var brush = Brushes.Orange;

 var container = new Rectangle(myViewModel.ContainerX, myViewModel.ContainerY,                                      myViewModel.ContainerWidth,                                              myViewModel.ContainerHeight);

 var stringFormat = new StringFormat {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};

 graphics.DrawString(customizationText, font, brush, container, stringFormat);
解决方案

Yes. Instead of DrawString, use the following sequence of calls:

If you need to use GraphicsPath.AddString alongside Graphics.DrawString, you need to convert the font sizes, because Graphics.DrawString expects "point size" while GraphicsPath.AddString expects "em size". The conversion formula is simply emSize = g.DpiY * pointSize / 72.

Here's a code example:

// assuming g is the Graphics object on which you want to draw the text
GraphicsPath p = new GraphicsPath();
p.AddString(
    "My Text String",             // text to draw
    FontFamily.GenericSansSerif,  // or any other font family
    (int) FontStyle.Regular,      // font style (bold, italic, etc.)
    g.DpiY * fontSize / 72,       // em size
    new Point(0, 0),              // location where to draw text
    new StringFormat());          // set options here (e.g. center alignment)
g.DrawPath(Pens.Black, p);
// + g.FillPath if you want it filled as well

这篇关于大纲文本与System.Drawing中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 07:00