How to automatically generate and display transparent GIF images on the ASP. NET page

Source: Internet
Author: User
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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.