我想编写一个接受字符串参数的函数" TEXT"和int参数为" DEGREE"并创建一个png图像写入" TEXT"用它旋转它" DEGREE"。
请任何人帮我写这个
感谢
编辑1)
我之前尝试过这个:
public System.Drawing.Bitmap WaterText(Bitmap MainImage,
string Text,
byte Alpha,
byte Size,
string FontName,
string StringColor,
byte MyStyle,
byte MyPosision)
{
FontStyle Style;
switch (MyStyle)
{
case 1:
Style = FontStyle.Regular;
break;
case 2:
Style = FontStyle.Bold;
break;
case 3:
Style = FontStyle.Italic;
break;
case 4:
Style = FontStyle.Underline;
break;
default:
Style = FontStyle.Regular;
break;
}
Florist.APPCode.Struct.TextPosision Posision;
switch (MyPosision)
{
case 1:
Posision = Florist.APPCode.Struct.TextPosision.Top;
break;
case 2:
Posision = Florist.APPCode.Struct.TextPosision.Middle;
break;
case 3:
Posision = Florist.APPCode.Struct.TextPosision.Bottom;
break;
default:
Posision = Florist.APPCode.Struct.TextPosision.Bottom;
break;
}
Graphics canvas = Graphics.FromImage(MainImage);
Color Color = HexToColor(StringColor,Alpha);
StringFormat strformat=new StringFormat();
strformat.Alignment = StringAlignment.Center;
switch (Posision)
{
case Florist.APPCode.Struct.TextPosision.Top:
strformat.LineAlignment = StringAlignment.Near;
break;
case Florist.APPCode.Struct.TextPosision.Middle:
//canvas.DrawString(Text, new Font(FontName, Size, Style), new SolidBrush(Color), 0, MainImage.Height/2);
strformat.LineAlignment = StringAlignment.Center;
break;
case Florist.APPCode.Struct.TextPosision.Bottom:
strformat.LineAlignment = StringAlignment.Far;
break;
default:
strformat.LineAlignment = StringAlignment.Center;
break;
}
canvas.DrawString(Text, new Font(FontName, Size,Style), new SolidBrush(Color),
new RectangleF(0, 0, MainImage.Width, MainImage.Height), strformat);
return MainImage;
}
但现在我要旋转文字
答案 0 :(得分:0)
您可以查看following article,其中说明了绘制图形时如何旋转字符串。它使用RotateTransform方法。
答案 1 :(得分:0)
在写出字符串之前,使用角度在Graphics
对象上应用RotateTransform
:
canvas.RotateTransform(angle);