刚刚学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()); 运行结果在我的相册里。
。net画一副对联
原创
©著作权归作者所有:来自51CTO博客作者mb630ec035bcfe8的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:C# 捕获窗体最大化和最小化事件
下一篇:清理缓存(转)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
一副图读懂8086栈结构
一副图读懂8086栈结构。
汇编 8086 栈结构 -
中了源码的毒,给你一副良药
这篇文章讲如何读源码,学会读源码确实挺重要的
ios 拦截器 子任务