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

      

  • 相关阅读:
    瀑布流-03-通过封装的自定义布局快速实现商品展示
    瀑布流-02-手把手教你封装自定义布局
    瀑布流-01-自定义布局实现绚丽的瀑布流
    CoreAnimation-09-模拟时钟
    CoreAnimation-08-CATransition
    CoreAnimation-07-CAAnimationGroup
    CoreAnimation-06-CAKeyframeAnimation
    CoreAnimation-05-CABasicAnimation
    CoreAnimation-04-核心动画必备基础
    logstash+elasticsearch 错误摘记
  • 原文地址:https://www.cnblogs.com/wgscd/p/13615069.html
Copyright © 2011-2022 走看看