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

      

  • 相关阅读:
    HDOJ_1010 Tempter of the Bone
    矩阵旋转
    HDU 2544 最短路 http://acm.hdu.edu.cn/showproblem.php?pid=2544
    题目连接:http://acm.zznu.edu.cn/problem.php?id=1329
    队列/优先队列(代码简单模式)
    虚拟方法调用
    Vim中分屏(整理)
    Java Web设计模式之依赖倒换原则
    Java Web 设计模式之开闭原则
    Java 2+2=5
  • 原文地址:https://www.cnblogs.com/wgscd/p/13615069.html
Copyright © 2020-2023  润新知