1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 usingSystem.Drawing;8 usingSystem.Drawing.Drawing2D;9 Ten Public Partial class_default:system.web.ui.page One { A protected voidPage_Load (Objectsender, EventArgs e) - { -Bitmap Bitmap =NewBitmap ( $, -); theGraphics graphics =graphics.fromimage (bitmap); - Graphics. Clear (color.white); -Rectangle Rectangle =NewRectangle (0,0, $, -); -LinearGradientBrush Mylineargradientbrush =NewLinearGradientBrush (Rectangle, Color.White, Color.green, lineargradientmode.forwarddiagonal); +Graphics. FillRectangle (Mylineargradientbrush,0,0, $, -); -System.IO.MemoryStream ms =NewSystem.IO.MemoryStream (); + bitmap. Save (ms,system.drawing.imaging.imageformat.jpeg); A response.clearcontent (); atResponse.contenttype="Image/jpeg"; - Response.BinaryWrite (Ms. ToArray ()); - } -}
ASP. NET GDI + draw rectangle gradient