Here, we use asp.net to generate an image based on parameters such as p, x, y, and x.
Here, we use asp.net to generate an image based on parameters such as p, x, y, and x.
<% @ WebHandler Language = "c #" Class = "ImgCropper_WebHandler" Debug = "true" %>
Using System;
Using System. Web;
Using System. Drawing;
Using System. IO;
Public class ImgCropper_WebHandler: IHttpHandler
{
Public void ProcessRequest (HttpContext context)
{
String Pic = Convert. ToString (context. Request ["p"]);
Int PointX = Convert. ToInt32 (context. Request ["x"]);
Int PointY = Convert. ToInt32 (context. Request ["y"]);
Int CutWidth = Convert. ToInt32 (context. Request ["w"]);
Int CutHeight = Convert. ToInt32 (context. Request ["h"]);
Int PicWidth = Convert. ToInt32 (context. Request ["pw"]);
Int PicHeight = Convert. ToInt32 (context. Request ["ph"]);
Context. Response. ContentType = "image/jpeg ";
ResetImg (System. Web. HttpContext. Current. Server. MapPath (Pic), PicWidth, PicHeight, PointX, PointY, CutWidth, CutHeight). WriteTo (context. Response. OutputStream );
}
Public MemoryStream ResetImg (string ImgFile, int PicWidth, int PicHeight, int PointX, int PointY, int CutWidth, int CutHeight)
{
Image imgPhoto = Image. FromFile (ImgFile );
Bitmap BMP hoto = new Bitmap (CutWidth, CutHeight, System. Drawing. Imaging. PixelFormat. Format24bppRgb );
Graphics gbmPhoto = Graphics. FromImage (BMP hoto );
GbmPhoto. drawImage (imgPhoto, new Rectangle (0, 0, CutWidth, CutHeight), PointX * imgPhoto. width/PicWidth, PointY * imgPhoto. height/PicHeight, CutWidth * imgPhoto. width/PicWidth, CutHeight * imgPhoto. height/PicHeight, GraphicsUnit. pixel );
MemoryStream ms2 = new MemoryStream ();
BMP hoto. Save (ms2, System. Drawing. Imaging. ImageFormat. Jpeg );
ImgPhoto. Dispose ();
GbmPhoto. Dispose ();
BMP hoto. Dispose ();
Return ms2;
}
Public bool IsReusable
{
Get
{
Return false;
}
}
}