本文整理汇总了C#中SoundInTheory.DynamicImage.Util.FastBitmap类的典型用法代码示例。如果您正苦于以下问题:C# FastBitmap类的具体用法?C# FastBitmap怎么用?C# FastBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastBitmap类属于SoundInTheory.DynamicImage.Util命名空间,在下文中一共展示了FastBitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyFilter
/// <summary>
/// Applies the filter to the specified <paramref name="bitmap"/>. This method
/// first calls <see cref="ImageReplacementFilter.GetDestinationDimensions(FastBitmap, out Int32, out Int32)" />
/// to calculate the size of the destination image. Then it calls
/// <see cref="ImageReplacementFilter.ApplyFilter(FastBitmap, DrawingContext, int, int)" />
/// which is where the overridden class implements its filter algorithm.
/// </summary>
/// <param name="bitmap">
/// Image to apply the <see cref="ImageReplacementFilter" /> to.
/// </param>
public override sealed void ApplyFilter(FastBitmap bitmap)
{
OnBeginApplyFilter(bitmap);
// get destination dimensions
int width, height;
bool shouldContinue = GetDestinationDimensions(bitmap, out width, out height);
if (!shouldContinue)
return;
DrawingVisual dv = new DrawingVisual();
ConfigureDrawingVisual(bitmap, dv);
DrawingContext dc = dv.RenderOpen();
ApplyFilter(bitmap, dc, width, height);
dc.Close();
RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(width, height);
rtb.Render(dv);
FastBitmap destination = new FastBitmap(rtb);
// copy metadata
// TODO
/*foreach (PropertyItem propertyItem in bitmap.InnerBitmap.PropertyItems)
destination.InnerBitmap.SetPropertyItem(propertyItem);*/
// set new image
bitmap.InnerBitmap = destination.InnerBitmap;
OnEndApplyFilter();
}
示例2: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
return new ContrastAdjustmentEffect
{
Level = (Level + 100) / 40.0
};
}
示例3: CreateImage
protected override sealed void CreateImage()
{
base.CreateImage();
Rect bounds = new Rect(StrokeWidth / 2, StrokeWidth / 2,
CalculatedWidth - StrokeWidth,
CalculatedHeight - StrokeWidth);
Brush brush = Fill.GetBrush();
PointCollection points = GetPoints(bounds);
PathGeometry geometry = CanonicalSplineHelper.CreateSpline(points, Roundness / 100.0, null, true, true, 0.25);
Pen pen = GetPen();
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
// Draw polygon.
dc.DrawGeometry(brush, pen, geometry);
dc.Close();
RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(CalculatedWidth, CalculatedHeight);
rtb.Render(dv);
Bitmap = new FastBitmap(rtb);
}
示例4: ApplyFilter
protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
{
Vector offsetSize = GetOffsetSize() + new Vector(Size, Size);
dc.PushTransform(new TranslateTransform(offsetSize.X, offsetSize.Y));
base.ApplyFilter(source, dc, width, height);
dc.Pop();
}
示例5: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
// Fill temporary graphics buffer with mask (currently always a rectangle).
DrawingVisual dv = new DrawingVisual
{
Effect = new BlurEffect
{
Radius = Radius,
KernelType = KernelType.Gaussian
}
};
DrawingContext dc = dv.RenderOpen();
dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
dc.Close();
RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(source.Width, source.Height);
rtb.Render(dv);
Brush blurredImage = new ImageBrush(rtb);
return new UnsharpMaskEffect
{
BlurMask = blurredImage,
Amount = Amount / 100.0,
Threshold = Threshold
};
}
示例6: GetDestinationDimensions
/// <summary>
/// Returns the dimensions of the output image.
/// </summary>
/// <param name="source">The source image.</param>
/// <param name="width">The desired width of the output image.</param>
/// <param name="height">The desired height of the output image.</param>
/// <returns><c>true</c> if the destination image should be created; otherwise <c>false</c>.
/// The <see cref="DropShadowFilter" /> always returns <c>true</c>.</returns>
protected override bool GetDestinationDimensions(FastBitmap source, out int width, out int height)
{
Vector padding = GetPadding();
width = source.Width + (int) Math.Ceiling(Math.Abs(padding.X));
height = source.Height + (int) Math.Ceiling(Math.Abs(padding.Y));
return true;
}
示例7: ApplyFilter
public override void ApplyFilter(ImageGenerationContext context, FastBitmap bitmap)
{
if (Width == Unit.Empty && Height == Unit.Empty)
throw new DynamicImageException("At least one of Width or Height must be set.");
string sourceFileName = Path.GetTempFileName();
try
{
bitmap.Save(sourceFileName);
string outputFileName = Path.GetTempFileName();
try
{
int width = (Width == Unit.Empty) ? bitmap.Width : Unit.GetCalculatedValue(Width, bitmap.Width);
int height = (Height == Unit.Empty) ? bitmap.Height : Unit.GetCalculatedValue(Height, bitmap.Height);
new CairWrapper(context).ProcessImage(sourceFileName, outputFileName, int.MaxValue,
width, height, ConvolutionType);
FastBitmap output = new FastBitmap(File.ReadAllBytes(outputFileName));
if (output.InnerBitmap != null)
bitmap.InnerBitmap = output.InnerBitmap;
}
finally
{
File.Delete(outputFileName);
}
}
finally
{
File.Delete(sourceFileName);
}
}
示例8: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
return new BrightnessAdjustmentEffect
{
Level = this.Level/100.0
};
}
示例9: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
// Get curves either from Curves collection or ACV file.
CurveCollection curves = GetCurves();
// Check that there are at least 4 curves.
if (curves.Count < 4)
throw new DynamicImageException(
"At least 4 curves (corresponding to Composite, Red, Green, Blue) must be specified.");
// Convert mathematical curve definitions into 4x256 lookup texture (Composite, Red, Green, Blue are the 4 "columns").
FastBitmap curvesLookup = new FastBitmap(4, 256);
curvesLookup.Lock();
for (int x = 0; x < 4; ++x)
{
IEnumerable<CurvePoint> points = curves[x].Points.Cast<CurvePoint>();
float[] xValues = points.Select(p => (float) p.Input).ToArray();
float[] yValues = points.Select(p => (float) p.Output).ToArray();
float[] derivatives = CubicSplineUtility.CalculateSpline(xValues, yValues);
for (int y = 0; y < 256; ++y)
curvesLookup[x, y] = Color.FromRgb((byte) CubicSplineUtility.InterpolateSpline(xValues, yValues, derivatives, y), 0, 0);
}
curvesLookup.Unlock();
return new CurvesEffect
{
CurvesLookup = new ImageBrush(curvesLookup.InnerBitmap)
};
}
示例10: ApplyFilter
/// <summary>
/// Applies the <see cref="ShinyFloorFilter" /> to the specified <paramref name="source"/>.
/// </summary>
/// <param name="source">The source image.</param>
/// <param name="dc"></param>
/// <param name="width"></param>
/// <param name="height"></param>
protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
{
// First, draw reflected image with an opacity mask.
int reflectionHeight = (int)(source.Height * (ReflectionPercentage / 100.0f));
dc.PushTransform(new TransformGroup
{
Children = new TransformCollection
{
new ScaleTransform {ScaleY = -1},
new TranslateTransform {Y = GetReflectionOffsetY(source) + reflectionHeight}
}
});
dc.PushOpacityMask(new LinearGradientBrush(
SWMColors.Transparent,
SWMColor.FromArgb((byte)(255.0f * (ReflectionOpacity / 100.0f)), 0, 0, 0),
new Point(0, 0),
new Point(0, 1)));
dc.DrawImage(new CroppedBitmap(source.InnerBitmap, new Int32Rect(0, source.Height - reflectionHeight, source.Width, reflectionHeight)),
new Rect(0, 0, source.Width, reflectionHeight));
dc.Pop();
dc.Pop();
// Draw original image.
dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
}
示例11: CreateImage
protected override sealed void CreateImage(ImageGenerationContext context)
{
base.CreateImage(context);
Rect bounds = new Rect(StrokeWidth / 2, StrokeWidth / 2,
CalculatedWidth - StrokeWidth,
CalculatedHeight - StrokeWidth);
Brush brush = Fill.GetBrush();
Pen pen = GetPen();
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
if (Roundness == 0)
dc.DrawRectangle(brush, pen, bounds);
else
dc.DrawRoundedRectangle(brush, pen, bounds, Roundness, Roundness);
dc.Close();
RenderTargetBitmap rtb = RenderTargetBitmapUtility.CreateRenderTargetBitmap(CalculatedWidth, CalculatedHeight);
rtb.Render(dv);
Bitmap = new FastBitmap(rtb);
}
示例12: GetEffect
protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
{
return new ColorTintEffect
{
Amount = Amount/100.0,
RequiredColor = Color.ToWpfColor()
};
}
示例13: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
return new EmbossEffect
{
Amount = Amount,
Width = Width/(double) source.Width
};
}
示例14: GetEffect
protected override Effect GetEffect(ImageGenerationContext context, FastBitmap source)
{
return new BlurEffect
{
KernelType = KernelType.Gaussian,
Radius = Radius,
RenderingBias = RenderingBias.Quality
};
}
示例15: GetEffect
protected override Effect GetEffect(FastBitmap source)
{
return new BlurEffect
{
KernelType = KernelType.Gaussian,
Radius = Radius,
RenderingBias = RenderingBias.Quality
};
}