本文整理汇总了C#中System.Web.Helpers.WebImage类的典型用法代码示例。如果您正苦于以下问题:C# WebImage类的具体用法?C# WebImage怎么用?C# WebImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebImage类属于System.Web.Helpers命名空间,在下文中一共展示了WebImage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:hhussain1629,项目名称:Hussain_Website,代码行数:27,代码来源:PostsController.cs
示例2: Create
public void Create(Gallery gallery = null,HttpPostedFileBase file = null,int galId=0)
{
byte[] newdata = null;
if (gallery != null)
{
var gall = new Gallery();
gall.GalleryMimeType = file.ContentType;
newdata = new WebImage(file.InputStream).GetBytes(null);
gall.GalleryTitle = gallery.GalleryTitle;
gall.GalleryData = newdata;
this.db.Galleries.Add(gall);
}
else {
Image image2 = new Image();
string str = Regex.Replace(file.FileName, @"\.\w+", string.Empty);
image2.ImageTitle = str;
image2.Sortindex = image2.ID+1;
image2.GalleryID = galId;
image2.ImageMimeType = file.ContentType;
newdata = new WebImage(file.InputStream).GetBytes(null);
image2.ImageData = newdata;
this.db.Images.Add(image2);
}
db.SaveChanges();
}
开发者ID:crew1248,项目名称:web_store,代码行数:27,代码来源:PhotoGalleryRepository.cs
示例3: 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;
}
开发者ID:jrolstad,项目名称:Domus,代码行数:13,代码来源:TempImageProvider.cs
示例4: Edit
public async Task<ActionResult> Edit(ProfileViewModel model, HttpPostedFileBase upload)
{
var user = _userManager.FindById(User.Identity.GetUserId());
if (user == null)
{
return RedirectToAction("Start", "Main");
}
if (upload != null && upload.ContentLength > 0)
{
WebImage img = new WebImage(upload.InputStream);
if (img.Width > 32)
img.Resize(32, 32);
user.Avatar = img.GetBytes();
}
user.FirstName = model.FirstName;
user.LastName = model.LastName;
user.UserName = model.Username;
user.Email = model.Email;
await _userManager.UpdateAsync(user);
return RedirectToAction("Details", "Profile");
}
开发者ID:squla,项目名称:projekt-zespolowy,代码行数:25,代码来源:ProfileController.cs
示例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);
}
开发者ID:NicolaNauwynck,项目名称:MVC-4-Cropper,代码行数:25,代码来源:HomeController.cs
示例6: Download
public ActionResult Download(int id, bool? thumb)
{
var context = HttpContext;
var mediaItem = Database.MediaItems.SingleOrDefault(m => m.Id == id);
if (mediaItem == null)
{
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
}
var filePath = Path.Combine(StorageRoot(mediaItem.MediaType), mediaItem.FileName);
if (!System.IO.File.Exists(filePath))
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
const string contentType = "application/octet-stream";
if (thumb.HasValue && thumb == true)
{
var img = new WebImage(filePath);
if (img.Width > 120)
img.Resize(120, 110).Crop(1, 1);
return new FileContentResult(img.GetBytes(), contentType)
{
FileDownloadName = mediaItem.FileName
};
}
else
{
return new FilePathResult(filePath, contentType)
{
FileDownloadName = mediaItem.FileName
};
}
}
开发者ID:kasparo,项目名称:ZaDvermiWeb,代码行数:32,代码来源:FileController.cs
示例7: Edit
public ActionResult Edit(long id, HttpPostedFileBase boxFile,
HttpPostedFileBase bdate,
HttpPostedFileBase box1,
HttpPostedFileBase box2,
HttpPostedFileBase box3,
HttpPostedFileBase box4)
{
var item = GetSession.Get<Setting>(id);
var homePath = Server.MapPath("~/public/userfiles/home/boximage.jpg");
if (boxFile != null)
{
boxFile.SaveAs(string.Format(homePath));
}
homePath = Server.MapPath("~/public/userfiles/home/bdate.jpg");
if (bdate != null)
{
bdate.SaveAs(string.Format(homePath));
}
homePath = Server.MapPath("~/public/userfiles/home/box1.jpg");
if (box1 != null)
{
var image = new WebImage(box1.InputStream);
image.Resize(500,212).Crop(1, 1).Save(string.Format(homePath));
}
homePath = Server.MapPath("~/public/userfiles/home/box2.jpg");
if (box2 != null)
{
var image = new WebImage(box2.InputStream);
image.Resize(500, 212).Crop(1, 1).Save(string.Format(homePath));
}
homePath = Server.MapPath("~/public/userfiles/home/box3.jpg");
if (box3 != null)
{
var image = new WebImage(box3.InputStream);
image.Resize(500, 212).Crop(1, 1).Save(string.Format(homePath));
}
homePath = Server.MapPath("~/public/userfiles/home/box4.jpg");
if (box4 != null)
{
var image = new WebImage(box4.InputStream);
image.Resize(500, 212).Crop(1, 1).Save(string.Format(homePath));
}
UpdateModel(item);
GetSession.Update(item);
return RedirectToAction("Edit");
}
开发者ID:Avimunk,项目名称:soglowek.tmgroup,代码行数:60,代码来源:SettingsController.cs
示例8: Thumbnail
public ActionResult Thumbnail(string id)
{
var repository = new TagRepository();
var tag = repository.GetTag(id);
var photoList = repository.GetPhotoList(id);
if (tag != null && photoList.Count > 0)
{
using (MultiThumbnailGenerator generator = new MultiThumbnailGenerator())
{
foreach (var photo in photoList)
{
using (var imageStream = new System.IO.MemoryStream(photo.FileContents))
{
using (var image = System.Drawing.Image.FromStream(imageStream))
{
generator.AddImage(image);
}
}
}
using (var outStream = new System.IO.MemoryStream())
{
generator.WritePngToStream(outStream);
var image = new WebImage(outStream);
image.Write();
}
}
return null;
}
return Redirect("~/Content/Images/gallery-empty.png");
}
开发者ID:csell5,项目名称:Demos,代码行数:34,代码来源:TagController.cs
示例9: Crop
public ActionResult Crop(Guid id)
{
if (!db.Resources.Any(x => x.ID == id)) throw new HttpException(404, "Resource not found.");
Resource res = db.Resources.Single(x => x.ID == id);
if (!res.Type.StartsWith("image")) return Content("You cannot crop a non-image resource!");
string path = Path.Combine(Server.MapPath("~/ResourceUploads"), id.ToString());
FileStream stream = new FileStream(path, FileMode.Open);
if (stream.Length == 0) throw new HttpException(503, "An internal server error occured whilst fetching the resource.");
byte[] streamBytes = new byte[stream.Length];
stream.Read(streamBytes, 0, (int)stream.Length);
stream.Close();
WebImage img = new WebImage(streamBytes);
CropForm form = new CropForm
{
ResourceID = id,
Type = res.Type,
Source = res.Source,
SourceTextColorID = res.SourceTextColorID,
OrigWidth = img.Width,
OrigHeight = img.Height
};
return View(form);
}
开发者ID:JamesP2,项目名称:ReviewSite,代码行数:26,代码来源:ResourceController.cs
示例10: 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);
}
开发者ID:Zerek,项目名称:edurate,代码行数:32,代码来源:CourseController.cs
示例11: GetImage
public ImageResult GetImage(int id, string hash, ImageHelper.ImageSize dimensions)
{
var image = imageService.Find(id);
var imageSize = ImageHelper.GetDefaultImageDimensions(dimensions);
if (image == null || image.Hash != hash)
{
return GetDefaultImage(dimensions);
}
var imageFile = ImageHelper.GetImageFilePath(image.Hash, image.CreateDate);
if (!System.IO.File.Exists(imageFile))
{
return GetDefaultImage(dimensions);
}
Response.AppendHeader("content-disposition", "attachment; filename=" + image.Name);
var webImage = new WebImage(imageFile);
ImageHelper.ResizeImage(ref webImage, imageSize.Width, imageSize.Height);
return new ImageResult {Image = webImage, ImageFormat = ImageHelper.GetImageFormat(image.Name)};
}
开发者ID:ppotapenko,项目名称:Gallery,代码行数:26,代码来源:ImageController.cs
示例12: 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 });
}
}
开发者ID:mistertommat,项目名称:AvatarUpload,代码行数:35,代码来源:AvatarController.cs
示例13: FileUpload
public ActionResult FileUpload(HttpPostedFileBase file)
{
if (file != null && file.ContentType.StartsWith("image/"))
{
WebImage img = new WebImage(file.InputStream);
if (img.Width > 178)
{
img.Resize(178, img.Height);
}
if (img.Height > 178)
{
img.Resize(img.Width, 178);
}
//string path = "C:\\Users\\dzlatkova\\Desktop\\Images";
//if (!Directory.Exists(path))
//{
// DirectoryInfo di = Directory.CreateDirectory(path);
// di.Attributes &= ~FileAttributes.ReadOnly;
//}
//string filePath = Path.Combine(path, Path.GetFileName(file.FileName));
//file.SaveAs(path);
db.Employers.FirstOrDefault(x => x.UserId == WebSecurity.CurrentUserId).Picture = img.GetBytes();
db.SaveChanges();
}
return RedirectToAction("Profile");
}
开发者ID:nikup,项目名称:occupie,代码行数:32,代码来源:EmployerController.cs
示例14: MakeThumbnail
public string MakeThumbnail(WebImage image, int? postId, bool reachedPicLimit)
{
var post = _ctx.Post.Where(p => p.Id == postId).SingleOrDefault();
image.Resize(110, 110, true, true);
var filename = Path.GetFileName(image.FileName).Replace(" ", "");
image.Save(Path.Combine("~/Thumbnails", filename));
var postImage = new ImageModel
{
ImageUrl = ("/Thumbnails/" + filename),
IsDeleted = false,
Post = post,
IsThumbnail = true
};
if (reachedPicLimit)
{
postImage.ImageUrl = "/Images/picLimit.png";
}
_ctx.Image.Add(postImage);
_ctx.SaveChanges();
return postImage.ImageUrl;
}
开发者ID:paradigm944,项目名称:TenantsVillage,代码行数:27,代码来源:UploadController.cs
示例15: CreateImage
public ActionResult CreateImage(string format, string id)
{
var relName = $"~/App_Data/covers/{id}.jpg";
var absName = Server.MapPath(relName);
if (!System.IO.File.Exists(absName))
{
return HttpNotFound();
}
var img = new WebImage(absName);
switch (format.ToLower())
{
case "thumb":
img.Resize(100, 1000).Write();
break;
case "medium":
img.Resize(300, 3000)
.AddTextWatermark("Ingars Movie Database")
.AddTextWatermark("Ingars Movie Database", "White", padding: 7)
.Write();
break;
default:
return HttpNotFound();
}
return new EmptyResult();
}
开发者ID:ProgramUtvikling,项目名称:mvckurs-sept-2015,代码行数:31,代码来源:ImageController.cs
示例16: UploadForm
public int UploadForm(HttpPostedFileBase file, bool thumbnail = true)
{
int num = -1;
if (file.ContentLength > 0)
{
if (file.ContentType.Contains("image"))
{
WebImage webImage = new WebImage(file.InputStream);
if (webImage != null)
{
string imageFormat = file.ContentType.Replace("image/", "");
string str = "upload_" + (object)DateTime.Now.Ticks;
webImage.Save(this._Path + str, imageFormat, true);
if (thumbnail)
{
webImage.Resize(this._ThumbHeight, this._ThumbWidth, true, false);
webImage.Crop(1, 1, 0, 0).Save(this._ThumbnailPath + str, imageFormat, true);
}
num = 1;
}
}
else
{
string str = "upload_" + (object)DateTime.Now.Ticks + new FileInfo(file.FileName).Extension;
TFile.StreamToFile(file.InputStream, this._Path + str);
}
}
return num;
}
开发者ID:groupapp,项目名称:git_gogo,代码行数:29,代码来源:TFile.cs
示例17: SubirImagen
public string SubirImagen(WebImage imagen, int dimensionMaxima)
{
if (imagen != null && EsUnArchivoImagen(imagen.FileName))
{
var nombreArchivoSubido = SubirImagen(imagen, dimensionMaxima, UrlImagenHelper.DirectorioImagenes);
return nombreArchivoSubido;
}
return string.Empty;
}
开发者ID:acapdevila,项目名称:Blog-MVC5,代码行数:9,代码来源:SubirArchivoImagenServicio.cs
示例18: UploadImage
public static void UploadImage(this CloudBlobContainer storageContainer, string blobName, WebImage image)
{
var blob = storageContainer.GetBlockBlobReference(blobName);
blob.Properties.ContentType = "image/" + image.ImageFormat;
using (var stream = new MemoryStream(image.GetBytes(), writable: false))
{
blob.UploadFromStream(stream);
}
}
开发者ID:acapdevila,项目名称:Blog-MVC5,代码行数:10,代码来源:AzureStorageService.cs
示例19: 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);
}
开发者ID:Gromila,项目名称:JustPhotoGallery,代码行数:10,代码来源:ImageProcessing.cs
示例20: FullImageSave
public static void FullImageSave(WebImage image)
{
if (image != null)
{
var filename = Path.GetFileName(image.FileName);
var filepath = Path.Combine(DefaulFull, filename);
image.Save(filepath);
}
}
开发者ID:galyna,项目名称:Toloka,代码行数:10,代码来源:ImagesSaveHelper.cs
注:本文中的System.Web.Helpers.WebImage类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论