日期:2014-05-17  浏览次数:20399 次

图片水印文字如何居中
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Bitmap btm = (Bitmap)Bitmap.FromFile(@"C:\Users\Administrator\Desktop\image\bak.png");

        Graphics g = Graphics.FromImage(btm);
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Far;
        sf.LineAlignment = StringAlignment.Center;
        g.DrawString("诚  聘  英  才", new Font("幼圆", 9), Brushes.White, new Rectangle(-67, 2, btm.Width, btm.Height), sf);
        btm.Save(@"C:\Users\Administrator\Desktop\image\bak1.gif", ImageFormat.Png);
        g.Dispose();
    }
}
我现在输出后的图片是在图片居中的,但是是写死的。要是修改下文字长度估计就不居中。有没有方法将不管文字多少,只要不超过图片的长度都居中。
水印图片?文字居中?asp.net?图片 图片?DrawString? Rectangle 水印

------解决方案--------------------
根据字号、字数和画布的大小,计算出绘图起点的x、y轴座标,算法你可以自己写写。
------解决方案--------------------
顶楼主,帮了我个忙
------解决方案--------------------
既然都实现了 还不速速结贴给分..求8分
------解决方案--------------------
帮你顶一下,我碰到这问题了