zoukankan      html  css  js  c++  java
  • c#使用GDI+简单绘图(二)

            // Create the in-memory bitmap where you will draw the image.
            // This bitmap is 300 pixels wide and 50 pixels high.
            Bitmap image = new Bitmap(300, 50);
    
            // get the graphics context
            Graphics g = Graphics.FromImage(image);
    
            // Draw a solid white rectangle.
            // Start from point (1, 1).
            // Make it 298 pixels wide and 48 pixels high.
            g.FillRectangle(Brushes.White, 1, 1, 298, 48);
    
            // load a font and use it to draw a string
            Font font = new Font("Impact", 20, FontStyle.Regular);
            g.DrawString("This is a test.", font, Brushes.Blue, 10, 5);
    
            // write the image to the output stream.
            image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
    
            // dispose of the context and the bitmap
            g.Dispose();
            image.Dispose();
            // Create the in-memory bitmap where you will draw the image.
            // This bitmap is 450 pixels wide and 100 pixels high.
            Bitmap image = new Bitmap(450, 100);
            Graphics g = Graphics.FromImage(image);
    
            // Ensure high-quality curves.
            g.SmoothingMode = SmoothingMode.AntiAlias;
    
            // Paint the background.
            g.FillRectangle(Brushes.White, 0, 0, 450, 100);
    
            // Add an ellipse.
            g.FillEllipse(Brushes.PaleGoldenrod, 120, 13, 300, 50);
            g.DrawEllipse(Pens.Green, 120, 13, 299, 49);
    
            // Draw some text using a fancy font.
            Font font = new Font("Harrington", 20, FontStyle.Bold);
            g.DrawString("Oranges are tasty!", font, Brushes.DarkOrange, 150, 20);
    
            // Add a graphic from a file.
            System.Drawing.Image orangeImage =
              System.Drawing.Image.FromFile(Server.MapPath("oranges.gif"));
            g.DrawImageUnscaled(orangeImage, 0, 0);
    
            // Render the image to the output stream.
            image.Save(Response.OutputStream,
             System.Drawing.Imaging.ImageFormat.Jpeg);
    
            // Clean up.
            g.Dispose();
            image.Dispose();


  • 相关阅读:
    INV*更新物料信息
    WPF设置样式的几种方式
    使用InternetGetConnectedState判断本地网络状态(C#举例)
    WinInet API详解
    WPF导航总结
    WPF中的命令与命令绑定导航
    WPF依赖属性相关博客导航
    关于WPF自定义控件(导航)
    WPF送走控件的focus方法
    MvvmLight学习篇—— Mvvm Light Toolkit for wpf/silverlight系列(导航)
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234127.html
Copyright © 2011-2022 走看看