//自动换行文字
private Image drawString(Image image,string text,RectangleF rectF,Font font,Brush brush) {
if (text != string.Empty && text != "" && text != null && image!=null) {
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawString(text, font, brush, rectF);
g.Dispose();
}
return image;
}
怎么才能设置 字间距和行间距?
6 个解决方案
#1
//设置字符间隔
[DllImport("gdi32.dll")]
public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);
#2
//gdi32.dll
原型:int SetTextCharacterExtra(HDC hdc, int nCharExtra);
#3
能嵌入 我的方法里吗 小白一个 你这样写 我不懂
#4
[DllImport("gdi32.dll")]
public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);
private Image drawString(Image image,string text,RectangleF rectF,Font font,Brush brush,int nCharExtra)
{
if (text != string.Empty && text != "" && text != null && image!=null)
{
Graphics g = Graphics.FromImage(image);
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc, nCharExtra);
g.ReleaseHdc(hdc);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawString(text, font, brush, rectF);
g.Dispose();
}
return image;
}
#5
不知道为什么没效果
#6
因为上面的方法是.net 2.0 .net 3.5 以上 请参考下面 链接里的方法。
http://www.cnblogs.com/geovindu/p/4315410.html
#1
//设置字符间隔
[DllImport("gdi32.dll")]
public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);
#2
//gdi32.dll
原型:int SetTextCharacterExtra(HDC hdc, int nCharExtra);
#3
//gdi32.dll
原型:int SetTextCharacterExtra(HDC hdc, int nCharExtra);
能嵌入 我的方法里吗 小白一个 你这样写 我不懂
#4
[DllImport("gdi32.dll")]
public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);
private Image drawString(Image image,string text,RectangleF rectF,Font font,Brush brush,int nCharExtra)
{
if (text != string.Empty && text != "" && text != null && image!=null)
{
Graphics g = Graphics.FromImage(image);
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc, nCharExtra);
g.ReleaseHdc(hdc);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawString(text, font, brush, rectF);
g.Dispose();
}
return image;
}
#5
[DllImport("gdi32.dll")]
public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);
private Image drawString(Image image,string text,RectangleF rectF,Font font,Brush brush,int nCharExtra)
{
if (text != string.Empty && text != "" && text != null && image!=null)
{
Graphics g = Graphics.FromImage(image);
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc, nCharExtra);
g.ReleaseHdc(hdc);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawString(text, font, brush, rectF);
g.Dispose();
}
return image;
}
不知道为什么没效果
#6
[DllImport("gdi32.dll")]
public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);
private Image drawString(Image image,string text,RectangleF rectF,Font font,Brush brush,int nCharExtra)
{
if (text != string.Empty && text != "" && text != null && image!=null)
{
Graphics g = Graphics.FromImage(image);
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc, nCharExtra);
g.ReleaseHdc(hdc);
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.High;
g.DrawString(text, font, brush, rectF);
g.Dispose();
}
return image;
}
不知道为什么没效果
因为上面的方法是.net 2.0 .net 3.5 以上 请参考下面 链接里的方法。
http://www.cnblogs.com/geovindu/p/4315410.html