本文整理汇总了C#中Functions.ResizeImage方法的典型用法代码示例。如果您正苦于以下问题:C# Functions.ResizeImage方法的具体用法?C# Functions.ResizeImage怎么用?C# Functions.ResizeImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Functions
的用法示例。
在下文中一共展示了Functions.ResizeImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
{
PictureRepository picRep = new PictureRepository();
Functions functions = new Functions();
// The Name of the Upload component is "attachments"
int NewPicID = picRep.GetLastPictureId(Convert.ToInt32(HttpContext.Session["ClientId"]));
NewPicID++;
Picture ins = new Picture();
foreach (var file in attachments)
{
// Some browsers send file names with full path. This needs to be stripped.
var fileName = Path.GetFileName(file.FileName);
var extention = fileName.Substring(fileName.IndexOf('.'));
var newfilename = NewPicID.ToString() + extention;
// Check if Path exsits
string serverpath = Server.MapPath("~/Images/Client/" + HttpContext.Session["ClientId"].ToString() + "/Ads");
if (!Directory.Exists(serverpath))
{
Directory.CreateDirectory(serverpath);
}
var physicalPath = Path.Combine(Server.MapPath("~/Images/Client/" + HttpContext.Session["ClientId"].ToString() + "/Ads"), newfilename);
//...Resize..
Image original = Image.FromStream(file.InputStream, true, true);
Image resized = functions.ResizeImage(original, new Size(500, 500));
resized.Save(physicalPath, ImageFormat.Jpeg);
string finalpath = physicalPath.ToString();
finalpath = finalpath.Substring(finalpath.IndexOf("Images"));
finalpath = finalpath.Replace('\\', '/');
//...Save In DB...
ins.PicUrl = Constants.HTTPPath + finalpath;
ins.ClientId = Convert.ToInt32(HttpContext.Session["ClientId"]);
ins = picRep.InsertPicture(ins);
}
// Return an empty string to signify success
if (ins.PictureId != 0)
return Json(new { status = ins.PictureId.ToString() }, "text/plain");
else
return Json(new { status = "0" }, "text/plain");
}