文字生产图片

private void CreateImage(string name, string filePath)
    {
        int wid = 400;
        int high = 20;
        Font font = new Font("Arial", 12, FontStyle.Bold);
        //绘笔颜色
        SolidBrush brush = new SolidBrush(Color.Black);
        Bitmap image = new Bitmap(wid, high);
        Graphics g = Graphics.FromImage(image);
        g.Clear(ColorTranslator.FromHtml("#f0f0f0"));
        RectangleF rect = new RectangleF(5, 2, wid, high);
        //绘制图片
        g.DrawString(name, font, brush, rect);
        //保存图片
        image.Save(Server.MapPath(filePath+"/22.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
        //释放对象
        g.Dispose();
        image.Dispose();
    }

你可能感兴趣的:(图片)