本文整理汇总了C#中System.Drawing.Bitmap.ForEachPixel方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.ForEachPixel方法的具体用法?C# Bitmap.ForEachPixel怎么用?C# Bitmap.ForEachPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.ForEachPixel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldIterateOverEveryPixel
public void ShouldIterateOverEveryPixel()
{
var image = new Bitmap(100, 100);
var pixels = new List<Tuple<int,int>>();
image.ForEachPixel((x, y) => pixels.Add(Tuple.Create(x, y)));
pixels.Distinct().Should().HaveCount(100 * 100);
}
示例2: ShouldIterateOverEveryPixelThatIsNotIgnored
public void ShouldIterateOverEveryPixelThatIsNotIgnored()
{
var image = new Bitmap(100, 100);
var pixels = new List<Tuple<int, int>>();
image.ForEachPixel(
(x, y) => pixels.Add(Tuple.Create(x, y)),
new[] { new IgnoreMask(0, 0, 9, 9) });
pixels.Distinct().Should().HaveCount((100 * 100) - (10 * 10));
}
示例3: GetCountOfPixelsThatMatch
private int GetCountOfPixelsThatMatch(Bitmap image)
{
var matchedPixels = 0;
image.ForEachPixel(
(x, y) =>
{
var pixelColor = image.GetPixel(x, y).ToArgb();
if (pixelColor == this.colorToMatch)
{
matchedPixels++;
}
});
return matchedPixels;
}
示例4: GetAverageColor
private static Color GetAverageColor(Bitmap image)
{
var colors = new List<Color>();
image.ForEachPixel(
(x, y) =>
{
var pixel = image.GetPixel(x, y);
colors.Add(Color.FromArgb(pixel.ToArgb()));
});
var averageColour = Color.FromArgb(
(int)colors.Average(color => color.R),
(int)colors.Average(color => color.G),
(int)colors.Average(color => color.B));
return averageColour;
}
示例5: AreEqual
public CompareResult AreEqual(Bitmap imageOne, Bitmap imageTwo)
{
if (imageOne.Width != imageTwo.Width) return new CompareResult { Equal = (false) };
if (imageOne.Height != imageTwo.Height) return new CompareResult { Equal = (false) };
var pixelsMatch = true;
imageOne.ForEachPixel(
(x, y) =>
{
var pixelOne = imageOne.GetPixel(x, y);
var pixelTwo = imageTwo.GetPixel(x, y);
if (pixelOne != pixelTwo)
{
pixelsMatch = false;
}
},
ignoreMasks);
return new CompareResult { Equal = (pixelsMatch) };
}