本文整理汇总了C#中ResizeSettings.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ResizeSettings.Add方法的具体用法?C# ResizeSettings.Add怎么用?C# ResizeSettings.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResizeSettings
的用法示例。
在下文中一共展示了ResizeSettings.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileStorage
public FileStorage(ISettings settings)
{
_settings = settings;
_resizeSettings = new ResizeSettings {
MaxWidth = settings.ThumbnailSize,
MaxHeight = settings.ThumbnailSize,
Format = "jpg"
};
_resizeSettings.Add("quality", ImageQuality);
//create FullsizedImagesFolder & SmallImagesFolder subfolders
string largeFilesFolder = Path.Combine(settings.ImagesLocalFolder, FullsizedImagesFolder);
string smallFilesFolder = Path.Combine(settings.ImagesLocalFolder, SmallImagesFolder);
if (!Directory.Exists(largeFilesFolder))
Directory.CreateDirectory(largeFilesFolder);
if (!Directory.Exists(smallFilesFolder))
Directory.CreateDirectory(smallFilesFolder);
_lastPhoto = Directory
.GetFiles(largeFilesFolder, "*.jpg")
.Select(i => int.Parse(Path.GetFileNameWithoutExtension(i).ToLower().Replace(".jpg", "")))
.OrderByDescending(i => i)
.FirstOrDefault();
if (_lastPhoto < 1)
_lastPhoto = 1;
}
示例2: Generate
//
// GET: /Image/
public FileResult Generate(string source, int width, int height)
{
string url = Uri.UnescapeDataString(source);
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebReponse.GetResponseStream();
var quality = 80;
byte[] resized;
using (var outStream = new MemoryStream())
{
var settings = new ResizeSettings
{
Mode = FitMode.Crop,
Width = width,
Height = height,
Format = "jpg"
};
settings.Add("quality", quality.ToString());
ImageBuilder.Current.Build(stream, outStream, settings);
resized = outStream.ToArray();
}
stream.Dispose();
return new FileStreamResult(new MemoryStream(resized, 0, resized.Length), "image/jpeg");
}
示例3: ScaleAndSavePhotos
private void ScaleAndSavePhotos(PhotoModel model, HttpRequestBase request)
{
var file = request.Files[0];
string extension = Path.GetExtension(file.FileName);
string filename = file.FileName;
//Copied Image and add watermark.
ResizeSettings settings = new ResizeSettings();
settings.Add("format", "jpg");
settings.Add("quality", "90");
settings.Add("carve", "true");
settings.Add("scale", "down");
settings.Add("mode", "carve");
if (model.Watermark)
{
settings.Add("watermark", "wm");
}
var path = Path.Combine(HttpContext.Current.Server.MapPath(string.Format("~/Albums/{0}", model.AlbumId)));
if (Directory.Exists(path))
{
//thumb is 75x75
//small is 240x159
//medium is 500 x 332
//large is 1024 x 680
Image img = Image.FromStream(file.InputStream);
//PropertyItem[] properties = img.PropertyItems;
//foreach (PropertyItem prop in properties)
//{
//}
bool vert = img.Height > img.Width;
settings.Add("maxwidth", vert ? "680" : "1024");
//settings.Add("maxheight", vert ? "1024" : "680");
Bitmap copy = ImageResizer.ImageBuilder.Current.Build(img, settings, false);
copy.Save(Path.Combine(path, "Large\\" + filename));
settings.Remove("maxwidth");
//settings.Remove("maxheight");
settings.Remove("watermark");
settings.Add("maxwidth", vert ? "332" : "500");
//settings.Add("maxheight", vert ? "500" : "332");
copy = ImageResizer.ImageBuilder.Current.Build(img, settings, false);
copy.Save(Path.Combine(path, "Medium\\" + filename));
settings.Remove("maxwidth");
//settings.Remove("maxheight");
settings.Remove("watermark");
settings.Add("maxwidth", vert ? "200" : "301");
//settings.Add("maxheight", vert ? "301" : "200");
copy = ImageResizer.ImageBuilder.Current.Build(img, settings, false);
copy.Save(Path.Combine(path, "Small\\" + filename));
settings.Remove("maxwidth");
settings.Remove("maxwidth");
settings.Remove("watermark");
settings.Add("maxwidth", "75");
settings.Add("maxheight", "75");
copy = ImageResizer.ImageBuilder.Current.Build(img, settings, false);
copy.Save(Path.Combine(path, "Thumb\\" + filename));
file.SaveAs(Path.Combine(path, "Original\\" + filename));
}
}