ASP. NET Image Generation has the built-in ImageResizeTransform class, which allows you to adjust the Image size.
You can also extend ImageTransform to implement your own image conversion class.
The following code uses the ASP. NET Image Generation watermark:
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Web;
- usingMicrosoft.Web;
- usingSystem.Collections.Specialized;
- usingSystem.Data.SqlClient;
- usingSystem.Drawing;
-
- namespaceNET35Lab.GeneratedImage.Web
- {
-
- publicclassImageHandler1:ImageHandler
- {
-
- publicImageHandler1()
- {
- this.ImageTransforms.Add(newImageResizeTransform
{Width=320,Mode=ImageResizeMode.Fit});
- this.ImageTransforms.Add(newCopyrightTransform{Text="Guushuuse.NET"});
- this.EnableClientCache=true;
- this.EnableServerCache=true;
-
- }
-
- publicoverrideImageInfoGenerateImage(NameValueCollectionparameters)
- {
-
- intintimageID=int.Parse(parameters["imageid"]);
-
- SqlConnectionconnection=newSqlConnection(
- @"DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.
mdf;IntegratedSecurity=True;UserInstance=True;");
-
- connection.Open();
-
- SqlCommandcommand=newSqlCommand
("selectimage_datafromt_imageswhereimage_id="+imageID,connection);
-
- SqlDataReaderdr=command.ExecuteReader();
-
- dr.Read();
-
- returnnewImageInfo((Byte[])dr[0]);
-
- }
- }
-
- publicclassCopyrightTransform:ImageTransform
- {
- privateconstintVERTICAL_PADDING=5;
- privateconstintHORIZONAL_PADDING=5;
-
- publicstringText{get;set;}
- publicFontFont{get;set;}
- publicColorFontColor{get;set;}
-
- publicCopyrightTransform()
- {
- //AssignDefaults
- FontColor=Color.FromArgb(128,255,0,0);
- Font=newFont("Courier",13);
- }
-
-
- publicoverrideSystem.Drawing.ImageProcessImage(System.Drawing.Imageimg)
- {
- GraphicsGraphicsgra=Graphics.FromImage(img);
- SizeFsz=gra.MeasureString(Text,Font);
- gra.DrawString(Text,Font,newSolidBrush(FontColor),
img.Width-sz.Width-HORIZONAL_PADDING,img.Height-sz.Height-VERTICAL_PADDING);
- returnimg;
- }
-
- publicoverridestringUniqueString
- {
- get
- {
- returnbase.UniqueString+Text+FontColor.ToString()+Font.ToString();
- }
- }
- }
- }
The above describes ASP. NET Image Generation.
- XML data displayed on the ASP. NET page
- What is iframe asp. NET?
- ASP. NET lifecycle display
- Solve the Problem of ASP. net ajax script errors
- ASP. NET Applications