本文整理汇总了C#中System.Pixel.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Pixel.GetLength方法的具体用法?C# Pixel.GetLength怎么用?C# Pixel.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Pixel
的用法示例。
在下文中一共展示了Pixel.GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Filter
public void Filter(IImage image, double[,] filter)
{
if (filter.GetLength(0) != filter.GetLength(1))
{
throw new ArgumentException("invalid filter", nameof(filter));
}
var result = new Pixel[image.Width, image.Height];
double blue = 0.0;
double green = 0.0;
double red = 0.0;
int filterOffset = (filter.GetLength(0) - 1) / 2;
for (int offsetY = filterOffset; offsetY < image.Height - filterOffset; offsetY++)
{
for (int offsetX = filterOffset; offsetX < image.Width - filterOffset; offsetX++)
{
blue = 0;
green = 0;
red = 0;
for (int filterY = -filterOffset; filterY <= filterOffset; filterY++)
{
for (int filterX = -filterOffset; filterX <= filterOffset; filterX++)
{
var imagePixel = image.GetPixel(offsetX + filterX, offsetY + filterY);
blue += (double)(imagePixel.B) * filter[filterY + filterOffset, filterX + filterOffset];
green += (double)(imagePixel.G) * filter[filterY + filterOffset, filterX + filterOffset];
red += (double)(imagePixel.R) * filter[filterY + filterOffset, filterX + filterOffset];
}
}
blue = Factor * blue + Bias;
green = Factor * green + Bias;
red = Factor * red + Bias;
result[offsetX, offsetY] = new Pixel { R = this.ToByte(red), G = this.ToByte(green), B = this.ToByte(blue) };
}
}
for (int x = 0; x < result.GetLength(0); x++)
{
for (int y = 0; y < result.GetLength(1); y++)
{
image.SetPixel(x, y, result[x, y]);
}
}
}