|
Server : Microsoft-IIS/10.0 System : Windows NT EBS-6136 10.0 build 17763 (Windows Server 2016) i586 User : jxgj ( 0) PHP Version : 7.0.33 Disable Function : passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server Directory : D:/tmp_aspnet/root/c87b3efd/cc6243dc/ |
?#pragma checksum "D:\wwwroot\zgyzd233com\wwwroot\App_Code\ImgHelper.cs" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "64C2884309DD88998D30051D956A2714"
#line 1 "D:\wwwroot\zgyzd233com\wwwroot\App_Code\ImgHelper.cs"
using System;
using System.Web;
using System.Web.UI.WebControls;
public class ImgHelper
{
public static string UpOriginalAndThumbnail_img(FileUpload uploadImage, double intimgWidth, double intimgHeight, string folderurl, string s_folderurl)
{
string imgname = DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss-fff");
HttpPostedFile hpf = uploadImage.PostedFile;
//获得文件名
string Filename = hpf.FileName;
if (hpf.FileName.Length < 1)
{
return ("*请选择你要上传的图片文件");
}
if (hpf.ContentType != "image/pjpeg" && hpf.ContentType != "image/gif")
{
return ("*只允许上传JPEG GIF文件");
}
else
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(imgname);
if (Filename.ToLower().EndsWith("gif"))
sb.Append(".gif");
else if (Filename.ToLower().EndsWith("jpg"))
sb.Append(".jpg");
else if (Filename.ToLower().EndsWith("jpeg"))
sb.Append(".jpeg");
Filename = sb.ToString();
//保留图片到服务器上
try
{
hpf.SaveAs(folderurl + Filename);
}
catch (Exception ee)
{
return ("*上传图片失败,原因:" + ee.Message);
}
//天生缩略图
//从文件获取图片对象
System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream,true);
Double Width = intimgWidth;
Double Height = intimgHeight;
System.Double newWidth, newHeight;
if (image.Width > image.Height)
{
newWidth = Width;
newHeight = image.Height * (newWidth / image.Width);
}
else
{
newHeight = Height;
newWidth = image.Width * (newHeight / image.Height);
}
if (newWidth > Width)
newWidth = Width;
if (newHeight > Height)
newHeight = Height;
System.Drawing.Size size = new System.Drawing.Size((int)newWidth, (int)newHeight); //设置图片的宽度和高度
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height); //新建bmp图片
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //新建画板
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //造订高质量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量、低快率出现滑润水平
g.Clear(System.Drawing.Color.White); //清空画布
//在造订地位画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(s_folderurl + Filename, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
return ("*保留缩略图失败" + ex.Message);
}
//开释资源
g.Dispose();
bitmap.Dispose();
image.Dispose();
return Filename;
}
}
public static void UpOriginalAndThumbnail_img(string originalImagePath, string thumbnailPath, double intimgWidth, double intimgHeight)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(originalImagePath,true);
Double Width = intimgWidth;
Double Height = intimgHeight;
System.Double newWidth, newHeight;
if (image.Height > Height || image.Width > Width)
{
if (image.Width > image.Height)
{
newWidth = Width;
newHeight = image.Height * (newWidth / image.Width);
}
else
{
newHeight = Height;
newWidth = image.Width * (newHeight / image.Height);
}
if (newWidth > Width)
newWidth = Width;
if (newHeight > Height)
newHeight = Height;
}
else
{
newWidth = image.Width;
newHeight = image.Height;
}
System.Drawing.Size size = new System.Drawing.Size((int)newWidth, (int)newHeight); //设置图片的宽度和高度
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height); //新建bmp图片
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //新建画板
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //造订高质量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量、低快率出现滑润水平
g.Clear(System.Drawing.Color.Transparent); //清空画布
//在造订地位画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
//开释资源
g.Dispose();
bitmap.Dispose();
image.Dispose();
}
}
}
#line default
#line hidden