本文整理汇总了C#中Draw.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# Draw.Convert方法的具体用法?C# Draw.Convert怎么用?C# Draw.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Draw
的用法示例。
在下文中一共展示了Draw.Convert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Distance
public override float Distance(Draw.Image other)
{
float result = 0;
if (other.IsNull())
result = float.MaxValue;
else if (!(other is YuvPacked))
using (YuvPacked o = other.Convert<YuvPacked>())
result = this.Distance(o);
else if (this.Size != other.Size)
using (YuvPacked o = other.ResizeTo(this.Size) as YuvPacked)
result = this.Distance(o);
else
{
for (int y = 0; y < this.Size.Height; y++)
for (int x = 0; x < this.Size.Width; x++)
{
Color.Yuv c = this[x, y];
Color.Yuv o = (other as YuvPacked)[x, y];
if (c.Distance(o) > 0)
{
Color.Yuv maximum = o;
Color.Yuv minimum = o;
for (int otherY = Integer.Maximum(0, y - this.DistanceRadius); otherY < Integer.Minimum(y + 1 + this.DistanceRadius, this.Size.Height); otherY++)
for (int otherX = Integer.Maximum(0, x - this.DistanceRadius); otherX < Integer.Minimum(x + 1 + this.DistanceRadius, this.Size.Width); otherX++)
if (otherX != x || otherY != y)
{
Color.Yuv pixel = (other as YuvPacked)[otherX, otherY];
if (maximum.Y < pixel.Y)
maximum.Y = pixel.Y;
else if (minimum.Y > pixel.Y)
minimum.Y = pixel.Y;
if (maximum.U < pixel.U)
maximum.U = pixel.U;
else if (minimum.U > pixel.U)
minimum.U = pixel.U;
if (maximum.V < pixel.V)
maximum.V = pixel.V;
else if (minimum.V > pixel.V)
minimum.V = pixel.V;
}
float distance = 0;
if (c.Y < minimum.Y)
distance += Single.Squared(minimum.Y - c.Y);
else if (c.Y > maximum.Y)
distance += Single.Squared(c.Y - maximum.Y);
if (c.U < minimum.U)
distance += Single.Squared(minimum.U - c.U);
else if (c.U > maximum.U)
distance += Single.Squared(c.U - maximum.U);
if (c.V < minimum.V)
distance += Single.Squared(minimum.V - c.V);
else if (c.V > maximum.V)
distance += Single.Squared(c.V - maximum.V);
result += Single.SquareRoot(distance) / 3;
}
}
result /= this.Size.Length;
}
return result;
}
示例2: Distance
public override float Distance(Draw.Image other)
{
Bgra o = other.Convert<Bgra>();
return this.Buffer.Distance(o.Buffer);
}
示例3: Distance
public override float Distance(Draw.Image other)
{
float result = 0;
if (other.IsNull())
result = float.MaxValue;
else if (!(other is Bgr))
using (Bgr o = other.Convert<Bgr>())
result = this.Distance(o);
else if (this.Size != other.Size)
using (Bgr o = other.ResizeTo(this.Size) as Bgr)
result = this.Distance(o);
else
{
for (int y = 0; y < this.Size.Height; y++)
for (int x = 0; x < this.Size.Width; x++)
{
Color.Bgr c = this[x, y];
Color.Bgr o = (other as Bgr)[x, y];
if (c.Distance(o) > 0)
{
Color.Bgr maximum = o;
Color.Bgr minimum = o;
for (int otherY = Integer.Maximum(0, y - this.DistanceRadius); otherY < Integer.Minimum(y + 1 + this.DistanceRadius, this.Size.Height); otherY++)
for (int otherX = Integer.Maximum(0, x - this.DistanceRadius); otherX < Integer.Minimum(x + 1 + this.DistanceRadius, this.Size.Width); otherX++)
if (otherX != x || otherY != y)
{
Color.Bgr pixel = (other as Bgr)[otherX, otherY];
if (maximum.Blue < pixel.Blue)
maximum.Blue = pixel.Blue;
else if (minimum.Blue > pixel.Blue)
minimum.Blue = pixel.Blue;
if (maximum.Green < pixel.Green)
maximum.Green = pixel.Green;
else if (minimum.Green > pixel.Green)
minimum.Green = pixel.Green;
if (maximum.Red < pixel.Red)
maximum.Red = pixel.Red;
else if (minimum.Red > pixel.Red)
minimum.Red = pixel.Red;
}
float distance = 0;
if (c.Blue < minimum.Blue)
distance += Single.Squared(minimum.Blue - c.Blue);
else if (c.Blue > maximum.Blue)
distance += Single.Squared(c.Blue - maximum.Blue);
if (c.Green < minimum.Green)
distance += Single.Squared(minimum.Green - c.Green);
else if (c.Green > maximum.Green)
distance += Single.Squared(c.Green - maximum.Green);
if (c.Red < minimum.Red)
distance += Single.Squared(minimum.Red - c.Red);
else if (c.Red > maximum.Red)
distance += Single.Squared(c.Red - maximum.Red);
result += Single.SquareRoot(distance) / 3;
}
}
result /= this.Size.Length;
}
return result;
}
示例4: Distance
public override float Distance(Draw.Image other)
{
float result = 0;
if (other.IsNull())
result = float.MaxValue;
else if (!(other is Monochrome))
using (Monochrome o = other.Convert<Monochrome>())
result = this.Distance(o);
else if (this.Size != other.Size)
using (Monochrome o = other.ResizeTo(this.Size) as Monochrome)
result = this.Distance(o);
else
{
for (int y = 0; y < this.Size.Height; y++)
for (int x = 0; x < this.Size.Width; x++)
{
Color.Monochrome c = this[x, y];
Color.Monochrome o = (other as Monochrome)[x, y];
if (c.Distance(o) > 0)
{
Color.Monochrome maximum = o;
Color.Monochrome minimum = o;
for (int otherY = Integer.Maximum(0, y - 2); otherY < Integer.Minimum(y + 3, this.Size.Height); otherY++)
for (int otherX = Integer.Maximum(0, x - 2); otherX < Integer.Minimum(x + 3, this.Size.Width); otherX++)
if (otherX != x || otherY != y)
{
Color.Monochrome pixel = (other as Monochrome)[otherX, otherY];
if (maximum.Y < pixel.Y)
maximum.Y = pixel.Y;
else if (minimum.Y > pixel.Y)
minimum.Y = pixel.Y;
}
float distance = 0;
if (c.Y < minimum.Y)
distance += Single.Squared(minimum.Y - c.Y);
else if (c.Y > maximum.Y)
distance += Single.Squared(c.Y - maximum.Y);
result += Single.SquareRoot(distance);
}
}
result /= this.Size.Length;
}
return result;
}
示例5: Create
public static Image Create(Draw.Image image)
{
Image result = null;
if (image is Raster.Image)
{
if (image is Raster.Bgra)
result = new Bgra(image as Raster.Bgra);
else if (image is Raster.Bgr)
result = new Bgr(image as Raster.Bgr);
else if (image is Raster.Monochrome)
result = new Monochrome(image as Raster.Monochrome);
else if (image is Raster.Yuv420)
result = new Yuv420(image as Raster.Yuv420);
else
result = new Bgra(image.Convert<Raster.Bgra>());
}
else if (image is Image)
result = image.Copy() as Image;
else if (image.NotNull())
result = new Bgra(image.Convert<Raster.Bgra>());
return result;
}