本文整理汇总了C#中System.Web.Helpers.WebImage.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# WebImage.GetBytes方法的具体用法?C# WebImage.GetBytes怎么用?C# WebImage.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Helpers.WebImage
的用法示例。
在下文中一共展示了WebImage.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
};
}
}
示例2: 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");
}
示例3: 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");
}
示例4: 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);
}
}
示例5: RotateImage
public JsonResult RotateImage(string url)
{
var image = new WebImage(_userImagesService.GetImageStream(url));
image.FileName = "rotated." + image.ImageFormat;
image.RotateLeft();
return
Json(
_userImagesService.SaveUserImageStream(
new MemoryStream(image.GetBytes()),
image.FileName,
image.ImageFormat, image.Height, image.Width),
"text/plain");
}
示例6: GetUserThumbnailImage
public ActionResult GetUserThumbnailImage(int userId, Guid userGuid)
{
try
{
UserDTO user = _managerService.UserDetails(userId, userGuid);
var img = new WebImage(user.AvatarImage);
img.Resize(32, 32, true, true);
return File(img.GetBytes("png"), "image/png");
}
catch (Exception ex)
{
Logger.LogError("GetUserImage: Exception while retrieving user avatar image data", ex);
return null;
}
}
示例7: GetSize
// GET: Photos
public ActionResult GetSize(int id)
{
Staff staff = db.StaffList.Find(id);
if (staff.Photo != null)
{
var img = new WebImage(staff.Photo);
img.Resize(100, 100, true, true);
var imgBytes = img.GetBytes();
return File(imgBytes, "image/" + img.ImageFormat);
}
else
{
return null;
}
}
示例8: AddWaterMark
public static byte[] AddWaterMark(string filePath, string text)
{
using (var img = System.Drawing.Image.FromFile(filePath))
{
using (var memStream = new MemoryStream())
{
using (var bitmap = new Bitmap(img)) // to avoid GDI+ errors
{
bitmap.Save(memStream, ImageFormat.Png);
var content = memStream.ToArray();
var webImage = new WebImage(memStream);
webImage.AddTextWatermark(text, verticalAlign: "Top", horizontalAlign: "Left", fontColor: "Brown");
return webImage.GetBytes();
}
}
}
}
示例9: Show
public ActionResult Show(Guid speakerId, int width, int height, string mode = "")
{
SpeakerPicture speakerPicture = service.TryGetPicture(speakerId);
if (speakerPicture == null)
return new HttpNotFoundResult();
var image = new WebImage(speakerPicture.Picture);
if (width > 0 && height > 0)
{
if (mode == "crop")
image = CropImage(image, width, height);
else
image = image.Resize(width, height);
}
return File(image.GetBytes(), image.ImageFormat);
}
示例10: CropImage
public JsonResult CropImage(string coords, string url)
{
var coordinates = new JavaScriptSerializer().Deserialize<Dictionary<string, int>>(coords);
var image = new WebImage(_userImagesService.GetImageStream(url));
image.FileName = "cropped." + image.ImageFormat;
image.Crop(
coordinates["y1"],
coordinates["x1"],
image.Height - coordinates["y2"],
image.Width - coordinates["x2"]);
return
Json(
_userImagesService.SaveUserImageStream(
new MemoryStream(image.GetBytes()),
image.FileName,
image.ImageFormat, image.Height, image.Width),
"text/plain");
}
示例11: ShowGuidWithWatermark
public ActionResult ShowGuidWithWatermark(string guid, string path, string width, string height)
{
int intWidth = 0;
int intHeight = 0;
if (!int.TryParse(width, out intWidth))
{
return null;
}
if (!int.TryParse(height, out intHeight))
{
return null;
}
if (string.IsNullOrWhiteSpace(guid) || string.IsNullOrWhiteSpace(path))
{
return null;
}
string photoName = "";
string coordinate = "";
var dc = new DbWithBasicFunction();
var db = dc.db;
if (path.ToLower() == "gallery")
{
var galleryItem = db.tbl_gallery.Where(a => a.guid == guid).FirstOrDefault();
if (galleryItem == null)
{
return null;
}
photoName = galleryItem.photo;
coordinate = galleryItem.photoCoordinate;
}
var item = getFileCoordinated(photoName, coordinate, path);
if (item != null)
{
var settings = new ResizeSettings();
int widthInt = int.Parse(width);
int heightInt = int.Parse(height);
settings.Width = widthInt;
settings.Height = heightInt;
settings.Mode = FitMode.Stretch;
WebImage waterMarkImage;
using (MemoryStream st = new MemoryStream())
{
ImageBuilder.Current.Build(item.First().Key, st, settings);
st.Position = 0;
waterMarkImage = new WebImage(st);
}
waterMarkImage.AddTextWatermark("www.titizkromaksesuar.com", fontColor: "#ffe27b", fontSize: 10, verticalAlign: "Middle", opacity: 60);
return File(waterMarkImage.GetBytes(), item.First().Value);
}
else
{
return null;
}
}
示例12: WaterMark
private Byte[] WaterMark(Stream s,string color)
{
MemoryStream str = new MemoryStream();
System.Web.Helpers.WebImage webimg = new System.Web.Helpers.WebImage(s);
String wm = WebSecurity.CurrentUserName;
webimg.AddTextWatermark(wm, color, 16, "Regular", "Microsoft Sans Serif", "Right", "Bottom", 50, 10);
return webimg.GetBytes();
}
示例13: GetDefaultPicture
public virtual UserPictureModel GetDefaultPicture(int size)
{
var image = new WebImage(HostingEnvironment.MapPath(Constants.DefaultProfilePicturePath));
image.Resize(size + 1, size + 1).Crop(1, 1);
return new UserPictureModel { Data = image.GetBytes(), ContentType = image.ImageFormat };
}
示例14: CreateNews
public ActionResult CreateNews(AddAchievement achievement, int ecologicalProblemID)
{
ViewBag.problemID = ecologicalProblemID;
int currentAdminId;
if (int.TryParse(Session["SystemUserId"].ToString(), out currentAdminId))
{
try
{
achievement.AchievementItem.Administrator = db.Administrators.Find(currentAdminId);
achievement.AchievementItem.EcologicalProblem = db.EcologicalProblems.Find(ecologicalProblemID);
if (achievement.ImageFile != null)
{
var image = new WebImage(achievement.ImageFile.InputStream);
image.Resize(200, 133);
achievement.AchievementItem.PhotoType = achievement.ImageFile.ContentType;
achievement.AchievementItem.PhotoFile = image.GetBytes();
}
db.Achivements.Add(achievement.AchievementItem);
db.SaveChanges();
return RedirectToAction("SystemNewsCreation");
}
catch { }
}
return View();
}
示例15: EditNews
public ActionResult EditNews(AddAchievement a)
{
var achievement = db.Achivements.Find(a.AchievementItem.AchievementID);
if (a.ImageFile != null)
{
var image = new WebImage(a.ImageFile.InputStream);
image.Resize(200, 133);
achievement.PhotoType = a.ImageFile.ContentType;
achievement.PhotoFile = image.GetBytes();
}
achievement.Title = a.AchievementItem.Title;
achievement.Description = a.AchievementItem.Description;
TryUpdateModel<Achievement>(achievement);
db.Entry<Achievement>(achievement).State = System.Data.EntityState.Modified;
db.SaveChanges();
return RedirectToAction("SystemNewsCreation");
}