Loading

C# WPF 根据RGB三色得出透明度Opacity

当我们把ARGB压缩为RGB数据时,会丢失A透明通道
那么就有可能会遇到反推A透明通道的问题
原理很简单,取RGB三色最大通道除255得到A通道

            Random random = new Random();

            byte red = Convert.ToByte(random.Next(0, 0xff));

            byte green = Convert.ToByte(random.Next(0, 0xff));

            byte blue = Convert.ToByte(random.Next(0, 0xff));

            byte[] numArray = new byte[] { red, green, blue };

            double opacity = Math.Round(numArray.Max() / 255.0, 2);
posted @ 2024-02-27 09:55  Stay627  阅读(48)  评论(0编辑  收藏  举报