Asp.net C# 图像处理
在aspx页面添加一个Image控件,其ImageUrl="Image.aspx",
添加一个Image.aspx,专门用来处理图像,在cs代码里的Page_Load事件处理中写上如下代码:
//原始图像
string physicalPath = Server.MapPath("./129519.jpg");
System.Drawing.Image srcBitmap = Bitmap.FromFile(physicalPath);
//想要的目标图像
int outHeight = srcBitmap.Height * 2;
int outWidth = srcBitmap.Width * 2;
//先创建一个空白的Bitmap
Bitmap outBitmap = new Bitmap(outWidth, outHeight, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(outBitmap);
//在outBitmap 上绘图
Rectangle destRectangle=new Rectangle(0, 0, outWidth, outHeight);
int srcX = 0;
int srcY = 0;
g.DrawImage(srcBitmap, destRectangle/*显示图像的大小*/, srcX,srcY/*从此X,Y坐标开始截取*/,srcBitmap.Width/4/*截取宽*/, srcBitmap.Height/4/*截取高*/, GraphicsUnit.Pixel);
//设置输出类型
Response.ContentType = "image/jpeg";
//向Client 输出
outBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
string physicalPath = Server.MapPath("./129519.jpg");
System.Drawing.Image srcBitmap = Bitmap.FromFile(physicalPath);
//想要的目标图像
int outHeight = srcBitmap.Height * 2;
int outWidth = srcBitmap.Width * 2;
//先创建一个空白的Bitmap
Bitmap outBitmap = new Bitmap(outWidth, outHeight, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(outBitmap);
//在outBitmap 上绘图
Rectangle destRectangle=new Rectangle(0, 0, outWidth, outHeight);
int srcX = 0;
int srcY = 0;
g.DrawImage(srcBitmap, destRectangle/*显示图像的大小*/, srcX,srcY/*从此X,Y坐标开始截取*/,srcBitmap.Width/4/*截取宽*/, srcBitmap.Height/4/*截取高*/, GraphicsUnit.Pixel);
//设置输出类型
Response.ContentType = "image/jpeg";
//向Client 输出
outBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();