zoukankan      html  css  js  c++  java
  • c# 将控件保存为图片

    Bitmap NewBitmap = new Bitmap(panel1.Width, panel1.Height);

                    panel1.DrawToBitmap(NewBitmap, new Rectangle(0, 0,NewBitmap.Width, NewBitmap.Height));

                   NewBitmap.Save(Application.StartupPath + @"..\Picture\LayOut\xx.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

         // MessageBox.Show(Application.StartupPath + @"\Picture\LayOut\xx.jpg");
                NewBitmap.Dispose();

    private void Page_Load(object sender, System.EventArgs e)
    {
    if ( !IsPostBack ){

    Bitmap newBitmap = new Bitmap(36,16,PixelFormat.Format32bppArgb);
    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap);
    g.FillRectangle(new SolidBrush(Color.White),new Rectangle(0,0,36,16));
    System.Drawing.Font textFont = new Font("Times new Roman",10);
    System.Drawing.RectangleF rectangle = new RectangleF(0,0,36,16);
    Random rd = new Random();
    int valationNo = rd.Next(1000,8999);
    g.FillRectangle(new SolidBrush(Color.BurlyWood),rectangle);
    g.DrawString(valationNo.ToString(),textFont,new SolidBrush(Color.Blue),rectangle);
    newBitmap.Save(Server.MapPath("img")+"\\19.gif",ImageFormat.Gif);

    g.Dispose();//记得释放资源
    newBitmap.Dispose();
    }
    }  

  • 相关阅读:
    326. Power of Three
    python实现Excel删除特定行、拷贝指定行操作
    283. Move Zeroes
    268. Missing Number
    263. Ugly Number
    258. Add Digits
    257. Binary Tree Paths
    二叉树的创建,递归前序、中序、后序遍历以及队列实现层遍历
    242. Valid Anagram
    237. Delete Node in a Linked List
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175855.html
Copyright © 2011-2022 走看看