检查图片是否空白图片

       /// <summary>
        /// 检查图片是否空白图片
        /// </summary>
        /// <param name="img">Image</param>
        /// <returns>是否空白图片</returns>
        private static bool CheckTransparentImg(string fileNamePath)
        {
            bool blnIsTransparent = false;
            //加载位图
            System.Drawing.Bitmap bitMap = new System.Drawing.Bitmap(fileNamePath);
            //图片总像素
            int intAll = bitMap.Height * bitMap.Width;
            int intBrightnessCount = 0;
            //按像素遍历
            for (int intY = 0; intY < bitMap.Height; intY++)
            {
                for (int intX = 0; intX < bitMap.Width; intX++)
                {
                    System.Drawing.Color color = bitMap.GetPixel(intX, intY);
                    float dBrightness = color.GetBrightness();
                    //亮度小于0.2认为不透明
                    if (dBrightness < 0.2)
                    {
                        intBrightnessCount++;
                    }
                }
            }
            //释放资源
            bitMap.Dispose();
            //只需要把数量为200以下的,基本能把噪点去掉
            if (intBrightnessCount <= 200)
            {
                blnIsTransparent = true;
            }

            return blnIsTransparent;
        }

 

参考:

https://bbs.youkuaiyun.com/topics/392260702?list=lz

https://blog.youkuaiyun.com/Gary_888/article/details/90258837

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值