本文整理汇总了C#中ImageFactory.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ImageFactory.Update方法的具体用法?C# ImageFactory.Update怎么用?C# ImageFactory.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageFactory
的用法示例。
在下文中一共展示了ImageFactory.Update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformImage
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">
/// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
/// the image to process.
/// </param>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public Image TransformImage(ImageFactory factory, Image image, Image newImage)
{
using (Graphics graphics = Graphics.FromImage(newImage))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
// Overlay the image with some semi-transparent colors to finish the effect.
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(rectangle);
// Paint a burgundy rectangle with a transparency of ~30% over the image.
// Paint a blue rectangle with a transparency of 20% over the image.
using (SolidBrush brush = new SolidBrush(Color.FromArgb(77, 38, 14, 28)))
{
Region oldClip = graphics.Clip;
graphics.Clip = new Region(rectangle);
graphics.FillRectangle(brush, rectangle);
// Fill the blue.
brush.Color = Color.FromArgb(51, 29, 32, 59);
graphics.FillRectangle(brush, rectangle);
graphics.Clip = oldClip;
}
}
}
}
// Add brightness and contrast to finish the effect.
factory.Update(newImage);
Brightness brightness = new Brightness { DynamicParameter = 5 };
newImage = (Bitmap)brightness.ProcessImage(factory);
factory.Update(newImage);
Contrast contrast = new Contrast { DynamicParameter = 85 };
newImage = (Bitmap)contrast.ProcessImage(factory);
// Reassign the image.
image.Dispose();
image = newImage;
return image;
}
示例2: TransformImage
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">
/// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
/// the image to process.
/// </param>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public Image TransformImage(ImageFactory factory, Image image, Image newImage)
{
using (Graphics graphics = Graphics.FromImage(newImage))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
}
// Add a vignette to finish the effect.
factory.Update(newImage);
Vignette vignette = new Vignette();
newImage = (Bitmap)vignette.ProcessImage(factory);
// Reassign the image.
image.Dispose();
image = newImage;
return image;
}
示例3: ApplyProcessor
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="processor">
/// The processor.
/// </param>
/// <param name="factory">
/// The factory.
/// </param>
private static void ApplyProcessor(Func<ImageFactory, Image> processor, ImageFactory factory)
{
ImageInfo imageInfo = factory.Image.GetImageInfo(factory.ImageFormat);
if (imageInfo.IsAnimated)
{
OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);
// We don't dispose of the memory stream as that is disposed when a new image is created and doing so
// beforehand will cause an exception.
MemoryStream stream = new MemoryStream();
using (GifEncoder encoder = new GifEncoder(stream, null, null, imageInfo.LoopCount))
{
foreach (GifFrame frame in imageInfo.GifFrames)
{
factory.Update(frame.Image);
frame.Image = quantizer.Quantize(processor.Invoke(factory));
encoder.AddFrame(frame);
}
}
stream.Position = 0;
factory.Update(Image.FromStream(stream));
}
else
{
factory.Update(processor.Invoke(factory));
}
// Set the property item information from any Exif metadata.
// We do this here so that they can be changed between processor methods.
if (factory.PreserveExifData)
{
foreach (KeyValuePair<int, PropertyItem> propertItem in factory.ExifPropertyItems)
{
try
{
factory.Image.SetPropertyItem(propertItem.Value);
}
// ReSharper disable once EmptyGeneralCatchClause
catch
{
// Do nothing. The image format does not handle EXIF data.
// TODO: empty catch is fierce code smell.
}
}
}
}
示例4: TransformImage
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="factory">
/// The the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing
/// the image to process.
/// </param>
/// <param name="image">The current image to process</param>
/// <param name="newImage">The new Image to return</param>
/// <returns>
/// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class.
/// </returns>
public Image TransformImage(ImageFactory factory, Image image, Image newImage)
{
using (Graphics graphics = Graphics.FromImage(newImage))
{
using (ImageAttributes attributes = new ImageAttributes())
{
attributes.SetColorMatrix(this.Matrix);
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
graphics.DrawImage(image, rectangle, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
// Add a glow to the image.
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(rectangle);
using (PathGradientBrush brush = new PathGradientBrush(path))
{
// Fill a rectangle with an elliptical gradient brush that goes from orange to transparent.
// This has the effect of painting the far corners transparent and fading in to orange on the
// way in to the centre.
brush.WrapMode = WrapMode.Tile;
brush.CenterColor = Color.FromArgb(70, 255, 153, 102);
brush.SurroundColors = new Color[] { Color.FromArgb(0, 0, 0, 0) };
Blend blend = new Blend
{
Positions = new float[] { 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0F },
Factors = new float[] { 0.0f, 0.5f, 1f, 1f, 1.0f, 1.0f }
};
brush.Blend = blend;
Region oldClip = graphics.Clip;
graphics.Clip = new Region(rectangle);
graphics.FillRectangle(brush, rectangle);
graphics.Clip = oldClip;
}
}
}
}
// Add a vignette to finish the effect.
factory.Update(newImage);
Vignette vignette = new Vignette();
newImage = (Bitmap)vignette.ProcessImage(factory);
// Reassign the image.
image.Dispose();
image = newImage;
return image;
}
示例5: ApplyProcessor
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="processor">
/// The processor.
/// </param>
/// <param name="factory">
/// The factory.
/// </param>
private static void ApplyProcessor(Func<ImageFactory, Image> processor, ImageFactory factory)
{
ImageInfo imageInfo = factory.Image.GetImageInfo(factory.ImageFormat);
if (imageInfo.IsAnimated)
{
OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);
// We don't dispose of the memory stream as that is disposed when a new image is created and doing so
// beforehand will cause an exception.
MemoryStream stream = new MemoryStream();
using (GifEncoder encoder = new GifEncoder(stream, null, null, imageInfo.LoopCount))
{
foreach (GifFrame frame in imageInfo.GifFrames)
{
factory.Update(frame.Image);
frame.Image = quantizer.Quantize(processor.Invoke(factory));
encoder.AddFrame(frame);
}
}
stream.Position = 0;
factory.Update(Image.FromStream(stream));
}
else
{
factory.Update(processor.Invoke(factory));
}
}