|
123456789101112131415161718192021222324252627 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.CustomResource.Pages.Model
- {
- internal class TextToImage
- {
- public Image CreateTextImage(string text, Font font, Color backgroundColor, Color foreColor, int margin = 5, RotateFlipType rotate = RotateFlipType.RotateNoneFlipNone)
- {
- SizeF sizeF = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(text, font);
- Bitmap bitmap = new Bitmap((int)sizeF.Width + margin * 2, (int)sizeF.Height + margin * 2);
- Graphics g = Graphics.FromImage(bitmap);
- g = Graphics.FromImage(bitmap);
- g.SmoothingMode = SmoothingMode.HighQuality;
- g.FillRegion(new SolidBrush(backgroundColor), g.Clip);
- g.DrawString(text, font, new SolidBrush(foreColor), margin, margin);
- g.Dispose();
- bitmap.RotateFlip(rotate);
- return bitmap;
- }
- }
- }
|