本文整理汇总了C#中ImageMagick.MagickImage.Histogram方法的典型用法代码示例。如果您正苦于以下问题:C# MagickImage.Histogram方法的具体用法?C# MagickImage.Histogram怎么用?C# MagickImage.Histogram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageMagick.MagickImage
的用法示例。
在下文中一共展示了MagickImage.Histogram方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadHistogram
private void LoadHistogram(FileItem fileItem, MagickImage bitmap)
{
fileItem.FileInfo.HistogramBlue = new int[256];
fileItem.FileInfo.HistogramGreen = new int[256];
fileItem.FileInfo.HistogramRed = new int[256];
fileItem.FileInfo.HistogramLuminance = new int[256];
Dictionary<MagickColor, int> h = bitmap.Histogram();
foreach (var i in h)
{
byte R = i.Key.R;
byte G = i.Key.G;
byte B = i.Key.B;
fileItem.FileInfo.HistogramBlue[B] += i.Value;
fileItem.FileInfo.HistogramGreen[G] += i.Value;
fileItem.FileInfo.HistogramRed[R] += i.Value;
int lum = (R + R + R + B + G + G + G + G) >> 3;
fileItem.FileInfo.HistogramLuminance[lum] += i.Value;
}
//fileItem.FileInfo.HistogramBlue = SmoothHistogram(fileItem.FileInfo.HistogramBlue);
//fileItem.FileInfo.HistogramGreen = SmoothHistogram(fileItem.FileInfo.HistogramGreen);
//fileItem.FileInfo.HistogramRed = SmoothHistogram(fileItem.FileInfo.HistogramRed);
//fileItem.FileInfo.HistogramLuminance = SmoothHistogram(fileItem.FileInfo.HistogramLuminance);
}
示例2: LoadHistogram
public void LoadHistogram(FileItem item)
{
try
{
var fileInfo = item.FileInfo;
if (fileInfo!=null)
{
if (fileInfo.IsLoading)
return;
fileInfo.IsLoading = true;
}
if (fileInfo == null || fileInfo.ExifTags == null || fileInfo.ExifTags.Items.Count == 0)
{
GetMetadata(item);
fileInfo = item.FileInfo;
fileInfo.IsLoading = true;
}
if (!File.Exists(item.SmallThumb))
{
fileInfo.IsLoading = false;
return;
}
using (MagickImage image = new MagickImage(item.SmallThumb))
{
var Blue = new int[256];
var Green = new int[256];
var Red = new int[256];
var Luminance = new int[256];
Dictionary<MagickColor, int> h = image.Histogram();
foreach (var i in h)
{
byte R = i.Key.R;
byte G = i.Key.G;
byte B = i.Key.B;
Blue[B] += i.Value;
Green[G] += i.Value;
Red[R] += i.Value;
int lum = (R + R + R + B + G + G + G + G) >> 3;
Luminance[lum] += i.Value;
}
fileInfo.HistogramBlue = Blue;
fileInfo.HistogramGreen = Green;
fileInfo.HistogramRed = Red;
fileInfo.HistogramLuminance = Luminance;
fileInfo.IsLoading = false;
item.FileInfo = fileInfo;
}
item.SaveInfo();
if (ServiceProvider.Settings.SelectedBitmap.FileItem == item)
{
SetData(ServiceProvider.Settings.SelectedBitmap,
ServiceProvider.Settings.SelectedBitmap.FileItem);
}
}
catch (Exception ex)
{
Log.Error("Unable to load histogram", ex);
}
//item.FileInfo.HistogramBlue = SmoothHistogram(item.FileInfo.HistogramBlue);
//item.FileInfo.HistogramGreen = SmoothHistogram(item.FileInfo.HistogramGreen);
//item.FileInfo.HistogramRed = SmoothHistogram(item.FileInfo.HistogramRed);
//item.FileInfo.HistogramLuminance = SmoothHistogram(item.FileInfo.HistogramLuminance);
}
示例3: Test_Histogram
public void Test_Histogram()
{
MagickImage image = new MagickImage(Files.RedPNG);
Dictionary<MagickColor, int> histogram = image.Histogram();
Assert.IsNotNull(histogram);
Assert.AreEqual(3, histogram.Count);
MagickColor red = new MagickColor(Quantum.Max, 0, 0);
MagickColor alphaRed = new MagickColor(Quantum.Max, 0, 0, 0);
MagickColor halfAlphaRed = new MagickColor("#FF000080");
foreach (MagickColor color in histogram.Keys)
{
if (color == red)
Assert.AreEqual(50000, histogram[color]);
else if (color == alphaRed)
Assert.AreEqual(30000, histogram[color]);
else if (color == halfAlphaRed)
Assert.AreEqual(40000, histogram[color]);
else
Assert.Fail("Invalid color: " + color.ToString());
}
image.Dispose();
}