zoukankan      html  css  js  c++  java
  • uwp 图像处理例子

        async  void test() {
    
    
                Color replaceBlack = Color.FromArgb(224,233,55,6);
                Color replaceWhite = Color.FromArgb(224, 233, 222, 222);
               // BitmapImage bmpimg = new BitmapImage();
        
    
               WriteableBitmap source = this.imageSource1.Source as WriteableBitmap; //need make sure the .imageSource1.Source is  WriteableBitmap
    
    
                byte[] byteArray = null;
                using (Stream stream = source.PixelBuffer.AsStream())
                {
                    long streamLength = stream.Length;
                    byteArray = new byte[streamLength];
                    await stream.ReadAsync(byteArray, 0, byteArray.Length);
                    if (streamLength > 0)
                    {
                        for (int i = 0; i < streamLength; i += 4)
                        {
                            if (byteArray[i + 3] != 0)
                            {
                                int b = Convert.ToInt32(byteArray[i]);
                                int g = Convert.ToInt32(byteArray[i + 1]);
                                int r = Convert.ToInt32(byteArray[i + 2]);
    
                                int rB = ((((b * replaceBlack.B) / 255) + (((255 - b) * replaceWhite.B) / 255)) / 2);
                                int rG = ((((g * replaceBlack.G) / 255) + (((255 - g) * replaceWhite.G) / 255)) / 2);
                                int rR = ((((r * replaceBlack.R) / 255) + (((255 - r) * replaceWhite.R) / 255)) / 2);
    
                                byte blue = Convert.ToByte(rB);
                                byte green = Convert.ToByte(rG);
                                byte red = Convert.ToByte(rR);
    
                                byteArray[i] = blue; // Blue
                                byteArray[i + 1] = green;  // Green
                                byteArray[i + 2] = red; // Red
                            }
                        }
                    }
                }
                if (byteArray != null)
                {
    
    
                    int lw, lh;
                    lw = source.PixelWidth;
                    lh = source.PixelHeight;
                    WriteableBitmap wbbitmap = new WriteableBitmap(source.PixelWidth, source.PixelHeight);
                    Stream s = wbbitmap.PixelBuffer.AsStream();
                    s.Seek(0, SeekOrigin.Begin);
    
                    s.Write(byteArray, 0, lw * lh * 3);
                    s.Flush();
    
                    this.imageTarget2.Source = null;
                    this.imageTarget2.Source = wbbitmap;
    
    
    
                }
    
    
    
    
            }
    

      

  • 相关阅读:
    nrf51822蓝牙芯片ble_app_proximity程序总结
    创新学分材料
    毕业论文 一定要自己写 切记不可抄袭​
    Shell awk 求标准差
    Java程序执行Linux命令(JSP运行其他程序)
    SFTP无法连接 Connection closed by server with exitcode 127
    IE开发人员工具手册
    jQuery plugins
    Google maps api demo 2
    Google maps api demo
  • 原文地址:https://www.cnblogs.com/wgscd/p/13615069.html
Copyright © 2011-2022 走看看