C#生成可旋转的文字图片

using System.Drawing;
using System.Drawing.Drawing2D;

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;
}

posted @ 2022-04-12 22:45  Bridgebug  阅读(157)  评论(0编辑  收藏  举报