Introduction to ASP. NET Image Generation

Source: Internet
Author: User

As Microsoft continues to expand and openSource codeScale. ASP. NET is the most popular project on codeplex.

There is an ASP. NET Image Generation sub-project under ASP. NET webforms, which facilitates Image Processing in ASP. NET projects.

 

Project Introduction: ASP. NET image generation is a speedy way of generating, transforming, caching images in Asp.net

Download: http://aspnet.codeplex.com/Wiki/View.aspx? Title = image % 20 generation & referringtitle = home

. NET Framework: 3.5

 

CodeExample:

Default. aspx

 

Code
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default "   %>

<% @ Register assembly = " Microsoft. Web. generatedimage " Namespace = " Microsoft. Web " Tagprefix = " PC3 "   %>

<!Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head Runat = "Server" >
< Title > </ Title >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" >
< Div >
< C0: generatedimage ID = "Generatedimage1"
Runat = "Server" Imagehandlerurl = "~ /Textimagehandler. ashx"   >
< Parameters >
< C0: imageparameter Name = "Hello" Value = "Text in an image"   />
</ Parameters >
</ C0: generatedimage >
</ Div >
</ Form >
</ Body >
</ Html >

 

Textimagehandler. ashx

Code
<% @ Webhandler Language = " C # " Class = " Textimagehandler "   %>

Using system;
Using system. Collections. Specialized;
Using system. drawing;
Using system. Web;
Using Microsoft. Web;

Public class textimagehandler: imagehandler {

Public textimagehandler (){
This. contenttype = system. Drawing. imaging. imageformat. PNG;
}

Public override imageinfo generateimage (namevaluecollection parameters ){
// Add image generation logic here and return an instance of imageinfo
Bitmap bit = new Bitmap (300, 60 );
Graphics gra = graphics. fromimage (BIT );
Gra. Clear (color. aliceblue );
Gra. drawstring (parameters ["hello"], new font (fontfamily. genericsansserif, 16), brushes. Black, 0, 0 );

Return new imageinfo (BIT );
}
}

 

Running Effect

 

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.