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;
            }

  • 相关阅读:
    Java基础之Comparable与Comparator
    Java基础之访问权限控制
    Java基础之抽象类与接口
    Java基础之多态和泛型浅析
    Spring MVC入门
    Spring框架之事务管理
    伸展树(Splay Tree)进阶
    2018牛客网暑期ACM多校训练营(第三场) A
    2018牛客网暑期ACM多校训练营(第三场) H
    HDU 6312
  • 原文地址:https://www.cnblogs.com/dreamzgj/p/2556559.html
Copyright © 2011-2022 走看看