本文整理匯總了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) };
}