zoukankan      html  css  js  c++  java
  • 在WEB程序中如何画图并显示

    大家都知道,在窗体上画图形,并显示出来很容易,只要得到相关容器的Graphics,就可以按照自己想要的样式去画;但是在WEB中,想要在某个页面中去随意画出图形并且显示出来则不能像窗体程序那样,因为不能获得某个容器的Graphics,这是B/S的架构有关,毕竟显示的页面是在Client,而你的处理地方是在Server端。

     

    那么如何在WEB程序中如何画图并显示,则需要一定设置,大致步骤如下:

     

    首先,需要设置WEB程序运行的目录下,设置一个临时目录,用于存放临时的图片文件,例如:“ImagesTemp”,并设置ASPNET用户能对此目录可写。

     

    接下来,画图的思路,是动态生成一个Bitmap,用它产生容器,从而得到Graphics;然后用此Graphics来画图;完毕后,把Bitmap中的内容保存到上面设置的临时目录中;再把页面中某个显示控件的ImageUrl指定到刚生成的图形临时文件,即可显示。大致代码如下:

           

    // Create panel

            Bitmap bitImage 
    = new Bitmap( 200200 );

     

            
    // Create graphics

            Graphics newGraphics 
    = Graphics.FromImage((System.Drawing.Image)bitImage);

     

            
    // Draw image

            newGraphics.FillRectangle(
    new SolidBrush(Color.Coral), 202012080);

     

            
    // Save image

            
    string strTempFileName = Server.MapPath( "Images" ) + "/ImgTemp.jpg";

            bitImage.Save( strTempFileName );

     

            
    // Draw image to screen.

            imgTest.ImageUrl 
    = @"Images/ImgTemp.jpg";

            
    // Release graphics object.

            newGraphics.Dispose();

            bitImage.Dispose();

  • 相关阅读:
    Python爬虫进阶五之多线程的用法
    Python爬虫进阶四之PySpider的用法
    Python爬虫进阶三之Scrapy框架安装配置
    Python爬虫进阶二之PySpider框架安装配置
    Python爬虫进阶一之爬虫框架概述
    Python爬虫利器六之PyQuery的用法
    Python爬虫利器五之Selenium的用法
    Python爬虫利器四之PhantomJS的用法
    Python爬虫利器三之Xpath语法与lxml库的用法
    Python爬虫利器二之Beautiful Soup的用法
  • 原文地址:https://www.cnblogs.com/kenter/p/2122972.html
Copyright © 2011-2022 走看看