。net画一副对联

刚刚学System.Graphics绘图方法,小小卖弄一下。画一幅对联。

 

      //实例化位图类和绘图类

        System.Drawing.Bitmap bmp=new Bitmap(300,150);
        System.Drawing.Graphics ghs = System.Drawing.Graphics.FromImage(bmp);

//情况背景色

        ghs.Clear(Color.Cyan);

        Font font = new Font("仿宋", 12);
        Pen white = new Pen(Color.White);
        Pen red = new Pen(Color.Red);

   //定义画刷
        Brush back=white.Brush;

        Brush rdBrush = red.Brush;

       
        StringFormat fomat=new StringFormat();
        fomat.FormatFlags = StringFormatFlags.DirectionVertical; 
        ghs.FillRectangle(back, 20, 30, 30, 120);
        ghs.FillRectangle(back,100 ,0, 100, 25);
        ghs.FillRectangle(back, 250, 30, 30, 120);

   //对联内容
        ghs.DrawString("时光易逝", font, rdBrush, 100, 0);
        ghs.DrawString("少壮不努力", font, rdBrush, 20, 30, fomat);
        ghs.DrawString("老大徒伤悲", font, rdBrush, 250, 30, fomat);

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        Response.ClearContent();
        Response.ContentType = "image/Gif";
        Response.BinaryWrite(ms.ToArray());

 运行结果在我的相册里。

你可能感兴趣的:(相册)