本文整理汇总了C#中System.Drawing.Imaging.ImageAttributes.SetOutputChannel方法的典型用法代码示例。如果您正苦于以下问题:C# ImageAttributes.SetOutputChannel方法的具体用法?C# ImageAttributes.SetOutputChannel怎么用?C# ImageAttributes.SetOutputChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Imaging.ImageAttributes
的用法示例。
在下文中一共展示了ImageAttributes.SetOutputChannel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResizeImageFitLongestSide
private static Bitmap ResizeImageFitLongestSide(Bitmap image, Size size, Color? spaceColor)
{
var colorSpace = spaceColor != null;
var sourceWidth = image.Width;
var sourceHeight = image.Height;
var nPercentW = ((float)sourceWidth / size.Width);
var nPercentH = ((float)sourceHeight / size.Height);
var nPercent = Math.Min(nPercentH, nPercentW);
var ufWidth = Math.Round(size.Width * nPercent);
if (ufWidth < size.Width && sourceWidth > ufWidth)
{
ufWidth = Math.Min(size.Width, sourceWidth);
}
var ufHeight = Math.Round(size.Height * nPercent);
if (ufHeight < size.Height && sourceHeight > ufHeight)
{
ufHeight = Math.Min(size.Height, sourceHeight);
}
var rect = new Rectangle((int)((sourceWidth - ufWidth) / 2),
(int)((sourceHeight - ufHeight) / 2), (int)ufWidth, (int)ufHeight);
var imageWidth = (int)Math.Min(ufWidth, size.Width);
var imageHeight = (int)Math.Min(ufHeight, size.Height);
if (!colorSpace)
{
var result = new Bitmap(imageWidth, imageHeight);
using (var graphics = Graphics.FromImage(result))
{
CustomizeGraphics(graphics);
graphics.DrawImage(Clone(image, rect), 0, 0, imageWidth, imageHeight);
}
return result;
}
else
{
var result = new Bitmap(size.Width, size.Height);
using (var graphics = Graphics.FromImage(result))
{
graphics.Clear(spaceColor.Value);
CustomizeGraphics(graphics);
var imgAttributes = new ImageAttributes();
imgAttributes.SetOutputChannel(ColorChannelFlag.ColorChannelC, ColorAdjustType.Bitmap);
var clone = Clone(image, rect);
graphics.DrawImage(clone,
(int)((float)(size.Width - imageWidth) / 2),
(int)((float)(size.Height - imageHeight) / 2),
imageWidth,
imageHeight);
}
return result;
}
}