c#绘制到图像中

来源:互联网 发布:hyper v 连不上网络 编辑:程序博客网 时间:2024/06/10 06:29
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing.Drawing2D;
  9. using System.Drawing.Imaging;
  10. namespace WindowsApplication2
  11. {
  12.     public partial class Form20 : Form
  13.     {
  14.         public Form20()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private void Form20_Load(object sender, EventArgs e)
  19.         {
  20.         }
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.             Rectangle rect = new Rectangle(0, 0, 100, 100);
  24.             Graphics dg = this.CreateGraphics();
  25.             Image image = new Bitmap(rect.Width, rect.Height, dg);
  26.             Graphics ig = Graphics.FromImage(image);
  27.             ig.FillRectangle(Brushes.Black, rect);
  28.             Font font = new Font("Arial", 12);
  29.             Brush brush = System.Drawing.Brushes.White;
  30.             ig.DrawString("zhuzhao", font, brush,0, 0);
  31.             //ImageFormat iformat=new ImageFormat(new Guid(Bmp));
  32.             image.Save(@"c:/image.png");
  33.             dg.DrawImage(image,new PointF(100,100));
  34.         }
  35.     }
  36. }
原创粉丝点击