判断一张图片的颜色数和亮度值
Posted littlehb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断一张图片的颜色数和亮度值相关的知识,希望对你有一定的参考价值。
static void Main(string[] args) { var di=new DirectoryInfo(@"C:UsersAdministratorDesktoppic"); foreach (var fi in di.GetFiles()) { var colorCount = 0; float lightness = 0; GetPicColorCountAndLightness(fi.FullName, out colorCount, out lightness); Console.WriteLine(fi.Name + " " + colorCount + " " + lightness); } Console.ReadKey(); } /// <summary> /// 功能:输入一个图片的路径,返回这张图片使用的颜色个数和亮度 /// 作者:黄海 /// 时间:2018-06-12 /// </summary> /// <param name="picPath"></param> /// <param name="colorCount"></param> /// <param name="lightNess"></param> /// <returns></returns> public static void GetPicColorCountAndLightness(string picPath,out int colorCount,out float lightNess) { var dict=new Dictionary<Color,int>(); var bmpobj = new Bitmap(picPath); float allLightness = 0; int count = 0; for (var i = 0; i < bmpobj.Height; i++) { for (var j = 0; j < bmpobj.Width; j++) { count++; var a=bmpobj.GetPixel(j, i); dict[a] = 1; //float hue = a.GetHue(); //float saturation = a.GetSaturation(); allLightness += a.GetBrightness(); } } colorCount = dict.Count; lightNess = allLightness; }
以上是关于判断一张图片的颜色数和亮度值的主要内容,如果未能解决你的问题,请参考以下文章
js进行数字图像处理:亮度对比度马赛克画笔放大缩小镜像贴纸旋转颜色值显示