Add an image control to the page and set its style attribute to: filter: chroma (color: #000000) Because automatically generated GIF images are always black backgrounds. Then write the following code in the background code. (See demo) using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. IO;
Using system. Drawing. drawing2d;
Namespace webpageindex
{
/** // <Summary>
/// Summary of webform1.
/// </Summary>
Public class webform1: system. Web. UI. Page
{
Protected system. Web. UI. htmlcontrols. htmlimage img1;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
Mytempimage = new mytempimage ();
Img1.src = mytempimage. createimage ();
}
Public class mytempimage: Page
{
Public String createimage ()
{
String STR = "xingzhong company financial seal ";
Bitmap image = new Bitmap (300,300 );
Graphics G = graphics. fromimage (image );
String thefullname = server. mappath ("/") + "\ nowtime.gif ";
Pen P = new pen (brushes. Red, 10 );
Pen p1 = new pen (brushes. Red, 5 );
Solidbrush B = new solidbrush (color. Red );
G. smoothingmode = smoothingmode. antialias;
Point point1 = new point (150, 50 );
Point point2 = new point (50,150 );
Point point3 = new point (230,150 );
Point [] curvepoints =
{
Point1,
Point2,
Point3,
};
G. fillpolygon (B, curvepoints, fillmode. Winding );
G. drawellipse (p, 10, 280,280 );
G. drawstring (STR, new font ("", 20, fontstyle. Bold), new
Solidbrush (color. fromargb (255,255, 0, 0), 40,200 );
G. drawline (P1, 80,240,220,240 );
G. drawline (P1, 80,250,220,250 );
Image. Save (thefullname, system. Drawing. imaging. imageformat. GIF );
Return "/nowtime.gif ";
}
}
Code generated by web form designer # code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/** // <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}
Running result diagram: