本文整理汇总了C#中System.Web.Helpers.WebImage.Save方法的典型用法代码示例。如果您正苦于以下问题:C# WebImage.Save方法的具体用法?C# WebImage.Save怎么用?C# WebImage.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Helpers.WebImage
的用法示例。
在下文中一共展示了WebImage.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public ActionResult Create([Bind(Include = "Id,Title,Slug,Body,MediaURL")] Post post, HttpPostedFileBase fileUpload)
{
if (ModelState.IsValid)
{
//Restricting the valid file formats to images only
if (fileUpload != null && fileUpload.ContentLength > 0)
{
if (!fileUpload.ContentType.Contains("image"))
{
return new HttpStatusCodeResult(HttpStatusCode.UnsupportedMediaType);
}
//var fileName = Path.GetFileName(fileUpload.FileName);
WebImage fileName = new WebImage(fileUpload.InputStream);
if (fileName.Width > 500)
fileName.Resize(500, 500);
//fileUpload.SaveAs(Path.Combine(Server.MapPath("~/assets/img/blog/"), fileName));
fileName.Save("~/assets/img/blog/"+fileUpload.FileName);
post.MediaURL = "~/assets/img/blog/" + fileUpload.FileName;
}
var cDate = DateTimeOffset.UtcNow;
post.CreationDate = cDate.ToLocalTime();
db.Posts.Add(post);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(post);
}
示例2: Save
/// <summary>
/// Saves an image to the temp directory with a given name
/// </summary>
/// <param name="image">Image to save</param>
/// <param name="fileName">Name of the file to save as</param>
/// <returns>Where the image is saved at</returns>
public virtual string Save(WebImage image, string fileName)
{
var path = GetFilePath(fileName);
image.Save(path);
return path;
}
示例3: Create
public ActionResult Create(CoursePostViewModel course)
{
if (ModelState.IsValid)
{
//saving image
var image = new WebImage(course.File.InputStream);
var imageName = Guid.NewGuid().ToString() + "." + image.ImageFormat;
var path = Path.Combine(Server.MapPath("~/Content/Images"), WebSecurity.CurrentUserName, "Courses");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = Path.Combine(path, imageName);
image.Save(path);
//saving course
var dbCourse = ViewModelIntoEntity(course);
dbCourse.CreatedDate = DateTime.Now;
dbCourse.LastModifiedDate = DateTime.Now;
dbCourse.Published = false;
dbCourse.ImageName = imageName;
dbCourse.ImageUrl = Path.Combine("~/Content/Images", WebSecurity.CurrentUserName, "Courses", imageName);
db.Courses.Add(dbCourse);
db.SaveChanges();
return RedirectToAction("Courses", "Dashboard");
}
ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", course.CategoryId);
ViewBag.InstructorId = WebSecurity.CurrentUserId;
return View(course);
}
示例4: Save
public ActionResult Save(string t, string l, string h, string w, string fileName)
{
try
{
// Calculate dimensions
var top = Convert.ToInt32(t.Replace("-", "").Replace("px", ""));
var left = Convert.ToInt32(l.Replace("-", "").Replace("px", ""));
var height = Convert.ToInt32(h.Replace("-", "").Replace("px", ""));
var width = Convert.ToInt32(w.Replace("-", "").Replace("px", ""));
// Get file from temporary folder
var fn = Path.Combine(Server.MapPath(MapTempFolder), Path.GetFileName(fileName));
// ...get image and resize it, ...
var img = new WebImage(fn);
img.Resize(width, height);
// ... crop the part the user selected, ...
img.Crop(top, left, img.Height - top - AvatarStoredHeight, img.Width - left - AvatarStoredWidth);
// ... delete the temporary file,...
System.IO.File.Delete(fn);
// ... and save the new one.
var newFileName = Path.Combine(AvatarPath, Path.GetFileName(fn));
var newFileLocation = HttpContext.Server.MapPath(newFileName);
if (Directory.Exists(Path.GetDirectoryName(newFileLocation)) == false)
{
Directory.CreateDirectory(Path.GetDirectoryName(newFileLocation));
}
img.Save(newFileLocation);
return Json(new { success = true, avatarFileLocation = newFileName });
}
catch (Exception ex)
{
return Json(new { success = false, errorMessage = "Unable to upload file.\nERRORINFO: " + ex.Message });
}
}
示例5: EditImage
public ActionResult EditImage(EditorInputModel editor)
{
string fileName = editor.Profile.ImageUrl;
var image = new WebImage(HttpContext.Server.MapPath("/Images/Temp/") + fileName);
double ratio = editor.Width / 620;
//the values to crop off.
double top = editor.Top * ratio;
double left = editor.Left * ratio;
double bottom = editor.Height - editor.Bottom * ratio;
double right = editor.Width - editor.Right * ratio;
image.Crop((int)top, (int)left, (int)bottom, (int)right);
//the image size I need at the end
image.Resize(620, 280);
image.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News"), fileName));
System.IO.File.Delete(Path.Combine(HttpContext.Server.MapPath("/Images/Temp/"), fileName));
var imageThumb = image;
imageThumb.Resize(65, 50);
imageThumb.Save(Path.Combine(HttpContext.Server.MapPath("/Images/News/Thumb"), fileName));
editor.Profile.ImageUrl = fileName;
return View("Index", editor.Profile);
}
示例6: CreateThumbnail
public void CreateThumbnail(String filename, String directory, int width, int height, String prefix = "thumb_")
{
var image = new WebImage(Path.Combine(directory, filename));
int newWidth = image.Width < image.Height ? image.Width*height/image.Height : width;
int newHeight = image.Width < image.Height ? height : image.Height*width/image.Width;
image.Resize(newWidth, newHeight, true).Crop(1, 1);
image.Save(Path.Combine(directory, String.Format("{0}{1}", prefix, filename)), image.ImageFormat);
}
示例7: CreateThumbnail
public static void CreateThumbnail(HttpPostedFileBase image, string folder)
{
var thumbnail = new WebImage(image.InputStream);
System.Diagnostics.Debug.WriteLine(thumbnail.FileName);
var fullPath = Path.Combine("~/" + folder + "/Thumbnails/", image.FileName);
thumbnail.Resize(thumbWidth, thumbHeight, true);
thumbnail.Save(fullPath, thumbnail.ImageFormat);
}
示例8: UploadImage
private ActionResult UploadImage(HttpPostedFileBase img, string sessionName)
{
var extension = Path.GetExtension(img.FileName);
var tempFileName = Guid.NewGuid();
var saveUrl = "~/ProfileImages/" + tempFileName + extension;
var image = new WebImage(img.InputStream);
image.Resize(150, 150);
image.Save(saveUrl);
Session.Add(sessionName, saveUrl);
return Content("<img src=\"/ProfileImages/" + tempFileName + extension + "\" alt=\"\" />");
}
示例9: SaveImage
private static void SaveImage(HttpPostedFileBase file, string filename)
{
WebImage img = new WebImage(file.InputStream);
if (img.Width > Settings.Default.MaxAuthorImageWidth)
{
int newWidth = Settings.Default.MaxAuthorImageWidth;
float aspectRatio = (float)img.Width / (float)img.Height;
int newHeight = Convert.ToInt32(newWidth / aspectRatio);
img.Resize(newWidth, newHeight).Crop(1, 1);
img.Save(filename);
}
}
示例10: saveImageToServer
public string saveImageToServer(WebImage image)
{
string folderPath = Server.MapPath(@"~/Images");
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
String newFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(image.FileName);
String fullPath = @"Images/" + newFileName;
image.Save(@"~/" + fullPath);
return newFileName;
}
示例11: ResizeAndSave
public void ResizeAndSave(Size newSize, string newPath = null)
{
if (string.IsNullOrEmpty(pathToFile))
return;
if (!File.Exists(pathToFile))
return;
WebImage webImage = new WebImage(pathToFile);
webImage.Resize(newSize.Width, newSize.Height);
webImage.Save(newPath ?? pathToFile);
}
示例12: uploadImage
public static void uploadImage(dynamic uploadedFile,ref String guids)
{
var fileSavePath = "";
BinaryReader b = new BinaryReader(uploadedFile.InputStream);
byte[] binData = b.ReadBytes(uploadedFile.ContentLength);
WebImage img= new WebImage(binData);
var guid=Guid.NewGuid().ToString();
guids = guids +""+guid+",";
fileSavePath = System.Web.HttpContext.Current.Server.MapPath("~/images/property/" +
guid);
img.Resize(imageWidth,imageHeight,true);
img.Save(fileSavePath,"jpg",true);
}
示例13: CropFile
public static void CropFile(string name, string diretorio, List<ImagensLayout.Tamanho> tamanhos)
{
var path = MontaPath(diretorio, name);
foreach (var item in tamanhos)
{
if (item.Nome == "Original")
continue;
var imagem = new WebImage(path);
var pathFotoCropada = MontaPath(diretorio, item.Altura + "x" + item.Largura + "_" + name);
imagem.Resize(item.Largura, item.Altura);
imagem.Save(pathFotoCropada);
}
}
示例14: SaveTemporaryAvatarFileImage
private static string SaveTemporaryAvatarFileImage(HttpPostedFileBase file, string serverPath, string fileName)
{
var img = new WebImage(file.InputStream);
var ratio = img.Height / (double)img.Width;
img.Resize(AvatarScreenWidth, (int)(AvatarScreenWidth * ratio));
var fullFileName = Path.Combine(serverPath, fileName);
if (System.IO.File.Exists(fullFileName))
{
System.IO.File.Delete(fullFileName);
}
img.Save(fullFileName);
return Path.GetFileName(img.FileName);
}
示例15: Crop
public ActionResult Crop(ImageModel imageModel)
{
WebImage image = new WebImage(_PATH + imageModel.ImagePath);
var height = image.Height;
var width = image.Width;
var top = imageModel.Top;
var left = imageModel.Left;
var bottom = imageModel.Bottom;
var right = imageModel.Right;
image.Crop(top, left, height - bottom, width - right);
image.Resize(140, 200, false, false);
image.Save(_PATH + imageModel.ImagePath);
return RedirectToAction("Index");
}