十、使用GDI+画图

使用的函数DrawIcon,DrawImage

DrawIcon(Icon,Rectangle)

DrawIcon(Icon,Int32,Int32)
private void Form1_Paint(object sender, PaintEventArgs e)
{    
    //创建画板从Paint事件中的直接引用Graphics对象
    Graphics graphics = e.Graphics;

    graphics.Clear(Color.Black);

    Icon icon = new Icon("test.ico",new Size(256,256));
    graphics.DrawIcon(icon, new Rectangle(100, 100, 300, 300));

注意:必须保证test.ico文件存在。

private void Form1_Paint(object sender, PaintEventArgs e)
{    
    //创建画板从Paint事件中的直接引用Graphics对象
    Graphics graphics = e.Graphics;

    graphics.Clear(Color.Black);

    /*Icon icon = new Icon("test.ico",new Size(256,256));
    graphics.DrawIcon(icon, new Rectangle(100, 100, 300, 300));*/
    Image image = Image.FromFile("test.png");
    graphics.DrawImage(image, new Point(100, 100));
}

posted on 2012-05-19 00:32  kiny  阅读(338)  评论(0编辑  收藏  举报