终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

28 行
1.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmartClient.CustomResource.Pages.Model
  9. {
  10. internal class TextToImage
  11. {
  12. public Image CreateTextImage(string text, Font font, Color backgroundColor, Color foreColor, int margin = 5, RotateFlipType rotate = RotateFlipType.RotateNoneFlipNone)
  13. {
  14. SizeF sizeF = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(text, font);
  15. Bitmap bitmap = new Bitmap((int)sizeF.Width + margin * 2, (int)sizeF.Height + margin * 2);
  16. Graphics g = Graphics.FromImage(bitmap);
  17. g = Graphics.FromImage(bitmap);
  18. g.SmoothingMode = SmoothingMode.HighQuality;
  19. g.FillRegion(new SolidBrush(backgroundColor), g.Clip);
  20. g.DrawString(text, font, new SolidBrush(foreColor), margin, margin);
  21. g.Dispose();
  22. bitmap.RotateFlip(rotate);
  23. return bitmap;
  24. }
  25. }
  26. }