本文整理汇总了C#中System.Drawing.Bitmap.GetGrayscaleBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetGrayscaleBytes方法的具体用法?C# Bitmap.GetGrayscaleBytes怎么用?C# Bitmap.GetGrayscaleBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetGrayscaleBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetectEdges
public static Bitmap DetectEdges(Bitmap original, ExchangeMask maskType)
{
var mask = masks[(int)maskType];
var current = new Bitmap(original.Width, original.Height);
var gsBytes = original.GetGrayscaleBytes();
for (var i = 0; i < current.Width; i++)
for (var j = 0; j < current.Height; j++) {
var newVal = GetSiblings(gsBytes, i, j)
.Zip(mask, (a, b) => a * b)
.Sum();
newVal = (newVal > limit) ? 255 : 0;
current.SetPixel(i, j, Color.FromArgb(255, newVal, newVal, newVal));
}
return current;
}
示例2: Equalize
public static Bitmap Equalize(Bitmap original)
{
var current = new Bitmap(original.Width, original.Height);
var oldLevels = original.GetGrayscaleBytes();
var newLevels = GetNewBrightnessLevels(oldLevels.Get1dArray());
for (var i = 0; i < original.Width; i++) {
for (var j = 0; j < original.Height; j++) {
var oldLevel = oldLevels[i, j];
var newLevel = newLevels[oldLevel];
current.SetPixel(i, j, Color.FromArgb(255, newLevel, newLevel, newLevel));
}
}
return current;
}
示例3: Normalize
public static Bitmap Normalize(Bitmap original)
{
var current = new Bitmap(original.Width, original.Height);
var gsBytes = original.GetGrayscaleBytes();
var gsBytesArr = gsBytes.Get1dArray();
var oldMin = gsBytesArr.Min();
var oldMax = gsBytesArr.Max();
var newMin = 0;
var newMax = 255;
for (var i = 0; i < current.Width; i++) {
for (var j = 0; j < current.Height; j++) {
var oldVal = gsBytes[i, j];
var newVal = (oldVal - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin;
current.SetPixel(i, j, Color.FromArgb(255, newVal, newVal, newVal));
}
}
return current;
}
示例4: Process
public static Bitmap Process(Bitmap image)
{
var current = new Bitmap(image.Width, image.Height);
var currentBin = new Bitmap(image.Width, image.Height);
var gs = image.GetGrayscaleBytes();
var binarized = Binarize(gs);
for (var i = 0; i < currentBin.Width; i++) {
for (var j = 0; j < currentBin.Height; j++) {
var tmp = binarized[i, j] == 1 ? Color.White : Color.Black;
currentBin.SetPixel(i, j, tmp);
}
}
var scanned = Scan(binarized);
var curColor = 0;
var colorsDict = new Dictionary<int, Color>();
for (var i = 0; i < current.Width; i++) {
for (var j = 0; j < current.Height; j++) {
var mark = scanned[i, j];
if (mark == 0) current.SetPixel(i, j, Color.White);
if (mark >= 2) {
Color tmpCol;
if (colorsDict.ContainsKey(mark)) tmpCol = colorsDict[mark];
else {
curColor = (curColor == colors.Count() - 1) ? 0 : curColor + 1;
colorsDict.Add(mark, colors[curColor]);
tmpCol = colors[curColor];
}
current.SetPixel(i, j, tmpCol);
}
}
}
currentBin.Save("SAVEDBIN.bmp");
current.Save("SAVED.bmp");
return current;
}