Winform画背景图片的两种方法TextureBrush与Graphics.DrawImage()

来源:互联网 发布:python中class的用法 编辑:程序博客网 时间:2024/06/05 20:23

1, 使用drawImage的例子:

private void DrawImage(Graphics g)        {            if (backImg == null)                return;            else                this.Size = backImg.Size;            Rectangle r = new Rectangle(0,0, this.Size.Width, this.Size.Height);            g.DrawImage(backImg, r);        }

2, 使用TextureBrush的例子:

using (Image image = Image.FromFile(@"e:\pic.jpg")) {     using (TextureBrush brush = new TextureBrush(image))     {         brush.TranslateTransform(x, y);         g.FillRectangle(brush, x, y, image.Width, image.Height);          g.Restore(state);      } }

简单区别参考:http://www.cnblogs.com/xingd/archive/2005/02/02/101047.html

原创粉丝点击