本文整理汇总了C#中ResizeSettings.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ResizeSettings.Get方法的具体用法?C# ResizeSettings.Get怎么用?C# ResizeSettings.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResizeSettings
的用法示例。
在下文中一共展示了ResizeSettings.Get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WicEncoderPlugin
public WicEncoderPlugin(ResizeSettings settings, object original)
: base(settings,original)
{
Dither = true;
Subsampling = settings["subsampling"];
this.Colors = -1;
//Parse colors
int colors = -1;
if (!string.IsNullOrEmpty(settings["colors"]))
if (int.TryParse(settings["colors"], out colors))
this.Colors = colors;
if ("false".Equals(settings["dither"], StringComparison.OrdinalIgnoreCase) ||
"0".Equals(settings["dither"], StringComparison.OrdinalIgnoreCase)) Dither = false;
Interlace = settings.Get<bool>("interlace");
}
示例2: GetOutputSize
private Size GetOutputSize(ResizeSettings settings, double boundingWidth, double boundingHeight)
{
// Output size is determined by resize settings, if available.
// maxwidth, maxheight
// – Fit the image within the specified bounds, preserving aspect ratio.
// width, height
// – Force the final width and/or height to certain dimensions.
// Whitespace will be added if the aspect ratio is different.
// This plugin renders to a size within the requested size and then expects remaining plugins in the
// pipeline to perform and additional processing such as adding whitespace, etc.
// It can safely treat width/height as maxwidth/maxheight.
double imageRatio = boundingWidth / boundingHeight;
double width = settings.Width;
double height = settings.Height;
double maxwidth = settings.MaxWidth;
double maxheight = settings.MaxHeight;
//Allow overrides with pdfwidth and pdfheight when we *want* to rescale afterwards.
int pw = settings.Get<int>("pdfwidth", -1);
int ph = settings.Get<int>("pdfheight", -1);
if (pw > 0) { width = pw; maxwidth = -1;}
if (ph > 0) { height = ph; maxheight = -1; }
//Handle cases of width/maxheight and height/maxwidth as in legacy versions.
if (width != -1 && maxheight != -1) maxheight = Math.Min(maxheight, (width / imageRatio));
if (height != -1 && maxwidth != -1) maxwidth = Math.Min(maxwidth, (height * imageRatio));
//Eliminate cases where both a value and a max value are specified: use the smaller value for the width/height
if (maxwidth > 0 && width > 0) { width = Math.Min(maxwidth, width); maxwidth = -1; }
if (maxheight > 0 && height > 0) { height = Math.Min(maxheight, height); maxheight = -1; }
//Move values to width/height
if (width <= 0) width = maxwidth;
if (height <= 0) height = maxheight;
//Calculate missing value(s)
if (width > 0 && height <= 0) height = width / imageRatio;
else if (height > 0 && width <= 0) width = height * imageRatio;
else if(width <= 0 && height <= 0) { // If neither width nor height as specified use default values
width = DefaultWidth;
height = DefaultHeight;
}
// Limit maximum output size
width = Math.Min(width, this.MaxWidth);
height = Math.Min(height, this.MaxHeight);
// Determine the scaling values, and use the smallest to ensure we fit in the bounding box without changing
// the aspect ratio otherwise we will crop.
//Use a scaled version of boundingBox inside our maximum width and height constraints.
return PolygonMath.RoundPoints(PolygonMath.ScaleInside(new SizeF((float)boundingWidth, (float)boundingHeight), new SizeF((float)width, (float)height)));
}
示例3: ApplyResizeSettings
private void ApplyResizeSettings(ResizeSettings settings, GhostscriptSettings ghostscriptSettings)
{
// Parse resize settings
// - graphicsAlphaBits
int graphicsAlphaBits = settings.GetValueOrDefault("graphicsbits", 0);
if(!_validAlphaBitValues.Contains(graphicsAlphaBits))
{
// Use default value
graphicsAlphaBits = _validAlphaBitValues.Last();
}
ghostscriptSettings.Add(GhostscriptArgument.GraphicsAlphaBits, graphicsAlphaBits);
// - textAlphaBits
int textAlphaBits = settings.GetValueOrDefault("textbits", 0);
if(!_validAlphaBitValues.Contains(textAlphaBits))
{
// Use default value
textAlphaBits = _validAlphaBitValues.Last();
}
ghostscriptSettings.Add(GhostscriptArgument.TextAlphaBits, textAlphaBits);
ghostscriptSettings[GhostscriptArgument.GridFitTT] = (settings.Get<bool>("gridfit") == true ? 2 : 0).ToString(NumberFormatInfo.InvariantInfo);
ghostscriptSettings[GhostscriptArgument.AlignToPixels] = (settings.Get<bool>("subpixels") == true ? 1 : 0).ToString(NumberFormatInfo.InvariantInfo);
if (settings.Get<bool>("printed",true) == false) ghostscriptSettings.Remove(GhostscriptArgument.Printed);
}
示例4: BuildLayout
/// <summary>
/// Build a layout for the source image given the resize settings
/// </summary>
/// <param name="imageSourceSize"></param>
/// <param name="resizeSettings"></param>
public ImageLayout BuildLayout(Size imageSourceSize, ResizeSettings resizeSettings)
{
// by default, we are taking the entire image
var sourceRectangle = new RectangleF(new PointF(0, 0), imageSourceSize);
var fit = resizeSettings.Mode;
// determine fit mode to use if both vertical and horizontal limits are used.
if (fit == FitMode.None)
{
if (resizeSettings.Width != -1 || resizeSettings.Height != -1)
{
// we specified both width and height
// we are looking for exact width and height then
// use pad to ensure height and width but ensure aspect ratio
// by adding padding where needed
fit = FitMode.Pad;
}
else
{
fit = FitMode.Max;
}
}
// Aspect source ratio of the image
var imageRatio = sourceRectangle.Size.Width / sourceRectangle.Size.Height;
// zoom factor
var zoom = resizeSettings.Get<double>("zoom", 1);
// The target size for the image
var imageSize = new SizeF(-1, -1);
// Target canvas size for the image
var canvasSize = new SizeF(-1, -1);
//If any dimensions are specified, calculate. Otherwise, use original image dimensions
if (resizeSettings.Width != -1 || resizeSettings.Height != -1 || resizeSettings.MaxHeight != -1 || resizeSettings.MaxWidth != -1)
{
// a dimension was specified.
// we first calculate the largest size the image can be under the width/height/maxwidth/maxheight restrictions.
// pretending stretch=fill and scale=both
// temp vars - results stored in targetSize and areaSize
double width = resizeSettings.Width;
double height = resizeSettings.Height;
double maxwidth = resizeSettings.MaxWidth;
double maxheight = resizeSettings.MaxHeight;
// eliminate cases where both a value and a max value are specified: use the smaller value for the width/height
if (maxwidth > 0 && width > 0) { width = Math.Min(maxwidth, width); maxwidth = -1; }
if (maxheight > 0 && height > 0) { height = Math.Min(maxheight, height); maxheight = -1; }
// handle cases of width/maxheight and height/maxwidth.
if (width != -1 && maxheight != -1) maxheight = Math.Min(maxheight, (width / imageRatio));
if (height != -1 && maxwidth != -1) maxwidth = Math.Min(maxwidth, (height * imageRatio));
//Move max values to width/height. FitMode should already reflect the mode we are using, and we've already resolved mixed modes above.
width = Math.Max(width, maxwidth);
height = Math.Max(height, maxheight);
// calculate missing value (a missing value is handled the same everywhere).
if (width > 0 && height <= 0)
height = width / imageRatio;
else if (height > 0 && width <= 0)
width = height * imageRatio;
// we now have width & height, our target size. It will only be a different aspect ratio from the image if both 'width' and 'height' are specified.
if (fit == FitMode.Max)
{
canvasSize = imageSize = PolygonMath.ScaleInside(sourceRectangle.Size, new SizeF((float)width, (float)height));
}
else if (fit == FitMode.Pad)
{
canvasSize = new SizeF((float)width, (float)height);
imageSize = PolygonMath.ScaleInside(sourceRectangle.Size, canvasSize);
}
else if (fit == FitMode.Crop)
{
canvasSize = new SizeF((float)width, (float)height);
imageSize = PolygonMath.RoundPoints(PolygonMath.ScaleOutside(canvasSize, sourceRectangle.Size));
}
else
{
// stretch
canvasSize = imageSize = new SizeF((float)width, (float)height);
}
}
else
{
// no dimensions specified, no fit mode needed.
canvasSize = imageSize = sourceRectangle.Size;
}
//.........这里部分代码省略.........