本文整理汇总了C#中ResizeSettings类的典型用法代码示例。如果您正苦于以下问题:C# ResizeSettings类的具体用法?C# ResizeSettings怎么用?C# ResizeSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResizeSettings类属于命名空间,在下文中一共展示了ResizeSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveImage
public Image SaveImage(HttpServerUtilityBase server, HttpPostedFileBase file)
{
string largeUploadFolder = server.MapPath("~/assets/images/large");
string mediumUploadFolder = server.MapPath("~/assets/images/medium");
string thumbUploadFolder = server.MapPath("~/assets/images/thumb");
if (!Directory.Exists(largeUploadFolder)) Directory.CreateDirectory(largeUploadFolder);
if (!Directory.Exists(mediumUploadFolder)) Directory.CreateDirectory(mediumUploadFolder);
if (!Directory.Exists(thumbUploadFolder)) Directory.CreateDirectory(thumbUploadFolder);
//The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
ResizeSettings largeSettings = new ResizeSettings("maxwidth=800&maxheight=800");
ResizeSettings mediumSettings = new ResizeSettings("maxwidth=300&maxheight=300&scale=both");
ResizeSettings thumbSettings = new ResizeSettings("width=100&height=100&crop=auto");
//var uniqueName = System.Guid.NewGuid().ToString();
string uniqueName = PathUtils.RemoveExtension(file.FileName) + "_" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss");
string largeFilePath = Path.Combine(largeUploadFolder, uniqueName);
string mediumFilePath = Path.Combine(mediumUploadFolder, uniqueName);
string thumbFilePath = Path.Combine(thumbUploadFolder, uniqueName);
//Let the image builder add the correct extension based on the output file type (which may differ).
var large = ImageBuilder.Current.Build(file, largeFilePath, largeSettings, false, true);
var med = ImageBuilder.Current.Build(file, mediumFilePath, mediumSettings, false, true);
var thumb = ImageBuilder.Current.Build(file, thumbFilePath, thumbSettings, false, true);
Image img = new Image(PathUtils.RemoveExtension(file.FileName), ResolveRelativePath(server, large), ResolveRelativePath(server, med), ResolveRelativePath(server, thumb));
Repo.Save(img);
return img;
}
示例2: CreateIfSuitable
public IEncoder CreateIfSuitable(ResizeSettings settings, object original)
{
if ("webp".Equals(settings.Format, StringComparison.OrdinalIgnoreCase)) {
return new WebPEncoderPlugin(settings);
}
return null;
}
示例3: Index
public FileContentResult Index(string filename, int w = 0, int h = 0)
{
try
{
string contentType = "";
var filePath = new FileInfo(Server.MapPath("~/App_Data/") + filename);
var index = filename.LastIndexOf(".") + 1;
var extension = filename.Substring(index).ToUpperInvariant();
// Fix for IE not handling jpg image types
contentType = string.Compare(extension, "JPG") == 0 ? "image/jpeg" : string.Format("image/{0}", extension);
Bitmap bmImage = null;
if (w > 0 && h > 0)
{
//&format={3}
string querySetting = String.Format("width={0};height={1};crop={2}", w, h, "auto");
var resizeSetting = new ResizeSettings(querySetting);
bmImage = ImageBuilder.Current.Build(filePath.FullName, resizeSetting);
}
else
{
bmImage = ImageBuilder.Current.LoadImage(filePath.FullName, new ResizeSettings());
}
byte[] byteArray = ImageHelpers.BitmapToBytes(bmImage);
return File(byteArray, contentType);
}
catch
{
throw new FileNotFoundException();
}
}
示例4: UploadFiles
public void UploadFiles(string settingsForImages)
{
if (!IsPostBack) return;
Guid lastUpload = Guid.Empty;
//Loop through each uploaded file
foreach (string fileKey in HttpContext.Current.Request.Files.Keys) {
HttpPostedFile file = HttpContext.Current.Request.Files[fileKey];
if (file.ContentLength <= 0) continue; //Yes, 0-length files happen.
if (Config.Current.Pipeline.IsAcceptedImageType(file.FileName) && settingsForImages != null) {
//The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details.
ResizeSettings resizeCropSettings = new ResizeSettings(settingsForImages);
using (MemoryStream ms = new MemoryStream()) {
//Resize the image
ImageBuilder.Current.Build(file, ms, resizeCropSettings);
//Upload the byte array to SQL
lastUpload = StoreFile(ms.ToArray(), ImageBuilder.Current.EncoderProvider.GetEncoder(resizeCropSettings, file.FileName).Extension, file.FileName);
}
} else {
//It's not an image - upload as-is.
lastUpload = StoreFile(StreamExtensions.CopyToBytes(file.InputStream), PathUtils.GetExtension(file.FileName).TrimStart('.'), file.FileName);
}
}
if (lastUpload != Guid.Empty) Response.Redirect(ResolveUrl("~/"));
}
示例5: ResizeImage
public static Bitmap ResizeImage(Stream imageStream, PhotoSize size)
{
var maxHeight = 0;
var maxWidth = 0;
switch (size)
{
case PhotoSize.Medium:
maxHeight = 225;
maxWidth = 225;
break;
case PhotoSize.Fullsize:
break;
default:
maxHeight = 125;
maxWidth = 125;
break;
}
var rs = new ResizeSettings();
if (maxHeight > 0)
{
rs.MaxHeight = maxHeight;
rs.MaxWidth = maxWidth;
}
return ImageBuilder.Current.Build(imageStream, rs);
}
示例6: 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");
}
示例7: GetImage
public Task<HttpResponseMessage> GetImage(string artistName, CancellationToken token)
{
return GetImageList(artistName, token).ContinueWith(imageTask =>
{
var response = new HttpResponseMessage();
var client = new WebClient();
var firstImage = imageTask.Result.FirstOrDefault();
if (!string.IsNullOrEmpty(firstImage))
{
var uri = new Uri(firstImage, UriKind.RelativeOrAbsolute);
if (!uri.IsAbsoluteUri)
{
uri = new Uri("http://2fm.rte.ie/images/default-album-art.jpg");
}
var query = Request.RequestUri.ParseQueryString();
var settings = new ResizeSettings(query);
var remote = RemoteReaderPlugin.Current.CreateSignedUrl(uri.ToString().Replace(" ", "%20"), settings);
var r = Request.CreateResponse(HttpStatusCode.Moved);
r.Headers.Location = new Uri(remote, UriKind.RelativeOrAbsolute);
return r;
//var imageStream = client.OpenRead(firstImage);
//response.Content = new StreamContent(imageStream);
//response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
//return response;
}
response.Content = new StreamContent(new MemoryStream());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
});
}
示例8: FreeImageEncoderPlugin
public FreeImageEncoderPlugin(ResizeSettings settings, object original)
{
ImageFormat originalFormat = DefaultEncoder.GetOriginalFormat(original);
if (!IsValidOutputFormat(originalFormat)) originalFormat = ImageFormat.Jpeg;//No valid info available about the original format. Use Jpeg.
//What format was specified?
ImageFormat requestedFormat = DefaultEncoder.GetRequestedFormat(settings.Format, originalFormat); //fallback to originalFormat if not specified.
if (!IsValidOutputFormat(requestedFormat))
throw new ArgumentException("An unrecognized or unsupported output format (" + (settings.Format != null ? settings.Format : "(null)") + ") was specified in 'settings'.");
this.format = FreeImage.GetFormat(requestedFormat);
//Parse JPEG settings.
int quality = 90;
if (string.IsNullOrEmpty(settings["quality"]) || !int.TryParse(settings["quality"], NumberStyles.Number, NumberFormatInfo.InvariantInfo, out quality)) quality = 90;
if (format == FREE_IMAGE_FORMAT.FIF_JPEG) {
if (quality >= 100) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB;
else if (quality >= 75)
encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD;
else if (quality >= 50) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYNORMAL;
else if (quality >= 25) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYAVERAGE;
else encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYBAD;
if ("true".Equals(settings["progressive"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_PROGRESSIVE;
if ("411".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_411;
if ("420".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_420;
if ("422".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_422;
if ("444".Equals(settings["subsampling"])) encodingOptions |= FREE_IMAGE_SAVE_FLAGS.JPEG_SUBSAMPLING_444;
}
if (string.IsNullOrEmpty(settings["colors"]) || !int.TryParse(settings["colors"], NumberStyles.Number, NumberFormatInfo.InvariantInfo, out colors)) colors = -1;
if (format == FREE_IMAGE_FORMAT.FIF_GIF) {
//encodingOptions = FREE_IMAGE_SAVE_FLAGS.
}
}
示例9: PrettyGifs
public PrettyGifs(ResizeSettings settings, object original)
{
this.query = new ResizeSettings(settings);
ResizeSettings q = settings;
//Parse output format
OutputFormat = GetFormatIfSuitable(settings, original);
//Parse colors
int colors = -1;
if (!string.IsNullOrEmpty(q["colors"]))
if (int.TryParse(q["colors"], NumberStyles.Integer,NumberFormatInfo.InvariantInfo, out colors))
this.Colors = colors;
//Parse dither settings
if (!string.IsNullOrEmpty(q["dither"])) {
if ("true".Equals(q["dither"], StringComparison.OrdinalIgnoreCase))
this.Dither = true;
else if ("4pass".Equals(q["dither"], StringComparison.OrdinalIgnoreCase))
this.FourPassDither = true;
else {
int dither;
if (int.TryParse(q["dither"], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out dither)) {
DitherPercent = dither;
Dither = true;
}
}
}
PreservePalette = q.Get<bool>("preservePalette", PreservePalette);
if (PreservePalette && original is Image && ((Image)original).Palette.Entries.Length > 0) {
originalPalette = ((Image)original).Palette;
}
}
示例10: SaveFile
public static string SaveFile(HttpPostedFileBase hpf, Photo_types type)
{
string filename = "",
ext = "",
savedFileName = "";
if (hpf.ContentLength == 0)
return "";
var settings = new ResizeSettings
{
MaxWidth = 450,
MaxHeight = 350,
Format = "jpg"
};
DateTime now = DateTime.Now;
ext = Path.GetExtension(hpf.FileName);
filename = type.ToString() + "-" + now.Millisecond + now.Second + now.Hour + now.Minute + now.Day + now.Year + ext;
savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + CMS_TEMP_PATH, filename);
ImageBuilder.Current.Build(hpf.InputStream, savedFileName, settings);
//hpf.SaveAs(savedFileName);
return filename;
}
示例11: ImageLayer
public ImageLayer(NameValueCollection attrs, Config c)
: base(attrs)
{
Path = attrs["path"];
this.c = c;
if (!string.IsNullOrEmpty(attrs["imageQuery"])) ImageQuery = new ResizeSettings(attrs["imageQuery"]);
}
示例12: Edit
public ActionResult Edit(EditModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
// Get the About entity if it exists, so ImageUrl doesn't get overriden to null if no image is selected and user is saving in json instead of sql.
var about = Services.About.Exists(model.Title) ? Services.About.GetByTitle(model.Title) : new About();
about.Name = model.Name;
about.Title = model.Title;
about.Content = model.Content;
// Save the image in blob storage
if (model.Image != null)
{
var image = new NBlog.Web.Application.Service.Entity.Image();
var fileName = Path.GetFileName(model.Image.FileName);
// Scale the image before saving
using (var scaledImageStream = new MemoryStream())
{
var settings = new ResizeSettings(200, 150, FitMode.None, "jpg");
ImageBuilder.Current.Build(model.Image.InputStream, scaledImageStream, settings);
image.StreamToUpload = scaledImageStream;
// Set FileName to save as, gets read as a repository key
image.FileName = fileName;
Services.Image.Save(image);
}
// Get the url to link to the About Entity
about.ImageUrl = Services.Image.GetByFileName(fileName).Uri;
}
Services.About.Save(about);
return RedirectToAction("Index", "About");
}
示例13: PostDecodeStream
protected override RequestedAction PostDecodeStream(ref Bitmap b, ResizeSettings settings)
{
if (!"true".Equals(settings["autorotate"], StringComparison.OrdinalIgnoreCase)) return RequestedAction.None;
int propertyId = 0x0112;
PropertyItem pi;
try {
pi = b.GetPropertyItem(propertyId);
} catch (ArgumentException) {
return RequestedAction.None;
}
if (pi == null) return RequestedAction.None;
int total = 0;
foreach (byte by in pi.Value) total += by; //Does not handle values larger than 255, but it doesn't need to, and is endian-agnostic.
if (total == 8) b.RotateFlip(RotateFlipType.Rotate270FlipNone);
if (total == 3) b.RotateFlip(RotateFlipType.Rotate180FlipNone);
if (total == 6) b.RotateFlip(RotateFlipType.Rotate90FlipNone);
if (total == 2) b.RotateFlip(RotateFlipType.RotateNoneFlipX);
if (total == 4) b.RotateFlip(RotateFlipType.Rotate180FlipX);
if (total == 5) b.RotateFlip(RotateFlipType.Rotate270FlipY);
if (total == 7) b.RotateFlip(RotateFlipType.Rotate90FlipY);
b.RemovePropertyItem(propertyId);
return RequestedAction.None;
}
示例14: ImageRequestAction
public ImageRequestAction(string virtualPath, NameValueCollection query, IPipelineConfig conf = null)
{
this.conf = (conf == null) ? Config.Current.Pipeline : conf;
ReauthorizeFinalPath = true;
Source = virtualPath;
Settings = new ResizeSettings(query);
}
示例15: 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;
}