zoukankan      html  css  js  c++  java
  • WPF 调节图片的明度(亮度)

    void SetBrightness(int brightness)
            {
                brightness = brightness * 255 / 100;

                WriteableBitmap wb = new WriteableBitmap(this.ImgViewBak.Source as BitmapSource);
                uint[] PixelData = new uint[wb.PixelWidth * wb.PixelHeight];
                wb.CopyPixels(PixelData, 4 * wb.PixelWidth, 0);
                for (uint y = 0; y < wb.PixelHeight; y++)
                {
                    for (uint x = 0; x < wb.PixelWidth; x++)
                    {
                        uint pixel = PixelData[y * wb.PixelWidth + x];
                        byte[] dd = BitConverter.GetBytes(pixel);
                        int B = (int)dd[0] + brightness;
                        int G = (int)dd[1] + brightness;
                        int R = (int)dd[2] + brightness;
                        if (B < 0) B = 0;
                        if (B > 255) B = 255;
                        if (G < 0) G = 0;
                        if (G > 255) G = 255;
                        if (R < 0) R = 0;
                        if (R > 255) R = 255;
                        dd[0] = (byte)B;
                        dd[1] = (byte)G;
                        dd[2] = (byte)R;
                        PixelData[y * wb.PixelWidth + x] = BitConverter.ToUInt32(dd, 0);
                    }
                }
                wb.WritePixels(new Int32Rect(0, 0, wb.PixelWidth, wb.PixelHeight), PixelData, 4 * wb.PixelWidth, 0);
                this.ImgView.Source = wb;
            }

  • 相关阅读:
    linux安装uwsgi,报错问题解决
    centos7 安装 mysql
    centos7 安装 redis
    Python 第三方登录 实现QQ 微信 微博 登录
    39个前端精美后台模板
    Excel中replace函数使用方法
    Excel实用录入技巧
    Excel的快速录入
    Excel表格规范
    Excel快捷键大全 Excel2013/2010/2007/2003常用快捷键大全
  • 原文地址:https://www.cnblogs.com/dreamzgj/p/2556559.html
Copyright © 2011-2022 走看看