国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

將文本文件或者字符串轉成,圖片

2019-11-02 14:18:51
字體:
來源:轉載
供稿:網友

   下面是一個將文本文件或者字符串轉成圖片的例子,調用方法:

  C# 代碼

  ConvertTextFileToImage(Server.MapPath("~/Data.txt"), Server.MapPath("~/Data.png"));

  實現的源代碼:

  C# 代碼

  protected void ConvertTextFileToImag

酷河馬電影網[www.aikan.tv/special/kuhemadianyingwang/]
e(String textFile, String imageFile)

  {

  const int FixedWidth = 1024;//期望的顯示寬度

  System.Drawing.Font drawFont = new System.Drawing.Font("宋體", 12);

  System.Drawing.Bitmap image = new System.Drawing.Bitmap(1, 1);

  System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);

  String text = System.IO.File.ReadAllText(textFile, System.Text.Encoding.GetEncoding("GB2312"));

  System.Drawing.SizeF sf = g.MeasureString(text, drawFont, FixedWidth);

  System.Drawing.Size showSize = new System.Drawing.Size(Convert.ToInt32(sf.Width), Convert.ToInt32(sf.Height));

  image = new System.Drawing.Bitmap(image, showSize);

  g = System.Drawing.Graphics.FromImage(image);

  g.Clear(System.Drawing.Color.White);

  g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

  g.DrawString(text, drawFont, System.Drawing.Brushes.Black, newSystem.Drawing.RectangleF(new System.Drawing.PointF(0, 0), sf));

  image.Save(imageFile, System.Drawing.Imaging.ImageFormat.Png);

  g.Dispose();

  image.Dispose();

  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沁源县| 塔城市| 宁远县| 惠州市| 扶余县| 房产| 保山市| 巴彦县| 资阳市| 敦化市| 巴塘县| 奎屯市| 彰化县| 都安| 平罗县| 曲阳县| 元江| 松滋市| 信宜市| 电白县| 财经| 自贡市| 诏安县| 平陆县| 桃园县| 英德市| 屏东县| 延吉市| 鱼台县| 南投县| 定远县| 怀化市| 安乡县| 惠水县| 乌鲁木齐县| 启东市| 玛沁县| 远安县| 佛坪县| 固始县| 互助|