本文整理汇总了C#中System.Windows.Media.LineSegment.Interpolate方法的典型用法代码示例。如果您正苦于以下问题:C# LineSegment.Interpolate方法的具体用法?C# LineSegment.Interpolate怎么用?C# LineSegment.Interpolate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.LineSegment
的用法示例。
在下文中一共展示了LineSegment.Interpolate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Airbrush
/// <summary>
/// Paints on a pbgra32 WriteableBitmap with a stylized airbrush
/// </summary>
/// <param name="bmp">The bitmap to modify</param>
/// <param name="from">The starting point of the stroke</param>
/// <param name="to">The end point of the stroke</param>
/// <param name="color">The color of the stroke</param>
/// <param name="size">The size of the stroke</param>
public static unsafe void Airbrush(WriteableBitmap bmp, Point from, Point to, Color color, int size)
{
Random r = new Random();
if (bmp == null) return;
bmp.Lock();
// Create a line segment representation
LineSegment segment = new LineSegment(from, to);
// Get a bounding box for the painted area
BoundingBox bitmapbounds = new BoundingBox();
BoundingBox segmentbounds = new BoundingBox();
bitmapbounds.AddPoint(0, 0, 0);
bitmapbounds.AddPoint(bmp.PixelWidth - 1, bmp.PixelHeight - 1, 0);
segmentbounds.AddPoint((int)from.X, (int)from.Y, size + AirbrushDotRadius);
segmentbounds.AddPoint((int)to.X, (int)to.Y, size + AirbrushDotRadius);
segmentbounds.Clip(bitmapbounds);
UInt32* start = (UInt32*)bmp.BackBuffer.ToPointer();
int stride = bmp.BackBufferStride / sizeof(UInt32);
// Move from 'from' to 'to' along timestep intervals, with one dot painted per interval
for (int i = 0; i < AirbrushDots; i++)
{
int x, y;
segment.Interpolate(i, AirbrushDots, out x, out y);
int dist = r.Next() % size;
double angle = r.NextDouble() * 2 * Math.PI;
double dx = Math.Cos(angle) * dist;
double dy = Math.Sqrt(dist * dist - dx * dx);
if(angle > Math.PI) dy = -dy;
int bx = x + (int)dx;
int by = y + (int)dy;
BoundingBox dotbounds = new BoundingBox();
dotbounds.AddPoint(bx,by,AirbrushDotRadius);
dotbounds.Clip(bitmapbounds);
for (int k = dotbounds.Top, row = 0; k < dotbounds.Bottom; k++, y++, row++)
for (int j = dotbounds.Left, col = 0; j < dotbounds.Right; j++, col++)
WriteAlphaBlended(start + stride * k + j, Color.FromArgb(AirbrushDotKernel[row][col], color.R, color.G, color.B));
}
bmp.AddDirtyRect(new Int32Rect(segmentbounds.Left, segmentbounds.Top, segmentbounds.Width, segmentbounds.Height));
bmp.Unlock();
}