中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C#在服務(wù)器端裁剪圖片代碼

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用

C#在服務(wù)器端裁剪圖片代碼

//圖片路徑
String oldPath = Server.MapPath("~/62223231.jpg");
  
//新圖片路徑
String newPath = System.IO.Path.GetExtension(oldPath);
  
//設(shè)置截取的坐標(biāo)和大小
int x = 0, y = 20, width = 200, height = 2400;
  
//計(jì)算新的文件名,在舊文件名后加_new
newPath = oldPath.Substring(0, oldPath.Length - newPath.Length) + "_new" + newPath;
Response.Write(oldPath);
Response.Write("<br>");
Response.Write(newPath);
//定義截取矩形
System.Drawing.Rectangle cropArea = new System.Drawing.Rectangle(x, y, width, height); //要截取的區(qū)域大小
  
//加載圖片
System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(oldPath)));
  
//判斷超出的位置否
if ((img.Width < x + width) || img.Height < y + height)
{
  Response.Write("截取的區(qū)域超過了圖片本身的高度、寬度.");
  img.Dispose();
  return;
}
//定義Bitmap對象
System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(img);
  
//進(jìn)行裁剪
System.Drawing.Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
  
//保存成新文件
bmpCrop.Save(newPath);
  
//釋放對象
img.Dispose();
bmpCrop.Dispose();

標(biāo)簽: isp 代碼 服務(wù)器 服務(wù)器端

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇: C# 計(jì)算輸入漢字的GBK編碼,十六進(jìn)制數(shù)輸出

下一篇:PHP計(jì)算地圖上兩點(diǎn)間的距離