62,269
社区成员
发帖
与我相关
我的任务
分享
Bitmap bmp = new Bitmap("C:\\map.jpg");
Rectangle rect = new Rectangle(0, 0, 200, 300);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(bmp, rect);
g.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 0, 0, 90, 90);
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Bitmap bigBmp=new Bitmap(Server.MapPath("map.jpg"));//map.jpg由于多张小图合成的一张大图,几万像素大小
Bitmap viewBmp = new Bitmap(viewWidth, viewHeight, PixelFormat.Format24bppRgb);
Rectangle viewRect = new Rectangle(0, 0, 500, 400);
Rectangle rect = new Rectangle(200, 100, 400, 300);
Graphics viewG = Graphics.FromImage(viewBmp);
viewG.Clear(Color.White);
viewG.SetClip(viewRect);
viewG.IntersectClip(rect);
viewG.DrawImageUnscaledAndClipped(bigBmp, viewRect);
viewBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
//大概意思,细节地方可能有错误。
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string file = context.Request.QueryString["file"];
int width= int.Parse(context.Request.QueryString["width"]);
int height= int.Parse(context.Request.QueryString["height"]);
DrawImage(context, file, width, height);
}
public bool IsReusable
{
get
{
return true;
}
}
private void DrawImage(HttpContext context, string file, int width, int height)
{
System.Drawing.Image img;
img = new Bitmap(width, height);
Graphics g = Graphics.FromImage(img);
g.DrawImage(new Bitmap(file), new Rectangle(0, 0, width, height)
, 0, 0, bmp.Width, bmp.Height
, GraphicsUnit.Pixel);
g.Dispose();
}
img.Save(context.Response.OutputStream, ImgTypeFormat);
img.Dispose();
}
}