zoukankan      html  css  js  c++  java
  • 【WIN10】WIN2D——圖層

    先看效果:

    效果還是不錯滴。

    這功能就有點像PS的圖層和蒙板了。

    簡單的添加一個層:

    private void draw_mb(CanvasControl sender, CanvasDrawingSession drawingSession)
    {
        draw_normal(sender, drawingSession);
        using (drawingSession.CreateLayer(1))
        {
            drawingSession.FillRectangle(0, 0, oriImage_.SizeInPixels.Width, oriImage_.SizeInPixels.Height, Color.FromArgb(128, 255, 255, 255));
        }
    }

    注意:一定要使用using,否則會出錯!!!!

    第二效果呢,先畫個模糊背景,再加一個圓就OK了,圓使用圖片填充,就可以顯示清晰的圓形圖片了~~~~~~

    private void draw_mb2(CanvasControl sender, CanvasDrawingSession drawingSession)
    {
        Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect gaussianEffect = new Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect();
        gaussianEffect.BlurAmount = 10;
        gaussianEffect.Source = oriImage_;
        drawingSession.DrawImage(gaussianEffect);
    
        float width = oriImage_.SizeInPixels.Width;
        float height = oriImage_.SizeInPixels.Height;
    
        using (drawingSession.CreateLayer(1))
        {
            Microsoft.Graphics.Canvas.Brushes.CanvasImageBrush br = new Microsoft.Graphics.Canvas.Brushes.CanvasImageBrush(sender);
            br.Image = oriImage_;
    
            drawingSession.FillCircle(new System.Numerics.Vector2(width / 2, height / 2-60), 60, br);
        }
    }

    第三個效果,也是相當簡單啦,第二個效果都出來了,第三個效果簡直就是複製粘貼那麼簡單:

    private void draw_mosaic(CanvasControl sender, CanvasDrawingSession drawingSession)
    {
        draw_normal(sender, drawingSession);
    
        float width = oriImage_.SizeInPixels.Width;
        float height = oriImage_.SizeInPixels.Height;
        using (drawingSession.CreateLayer(1f))
        {
            Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect gaussianEffect = new Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect();
            gaussianEffect.BlurAmount = 5;
            gaussianEffect.Source = oriImage_;
    
            Microsoft.Graphics.Canvas.Brushes.CanvasImageBrush br = new Microsoft.Graphics.Canvas.Brushes.CanvasImageBrush(sender);
            br.Image = gaussianEffect;
            br.SourceRectangle = new Rect(0, 0, width, height);
    
            drawingSession.FillCircle(new System.Numerics.Vector2(width / 2, height / 2 - 60), 60, br);
        }
    }

    PS:本來想用微軟的“微軟牛津計劃”的面部識別技術進行動態識別人臉。。。但是那個庫需要連網,而且不牆的話,網速不是很理想,所以就放棄了,使用固定的座標好了。

  • 相关阅读:
    无熟人难办事?—迪米特法则
    考题抄错会做也白搭—模板方法模式
    简历复印—原型模式
    Android Studio 安装及常见问题
    雷锋依然在人间——工厂方法模式
    欢迎测试
    客户端程序设计V1
    Linux服务器端程序设计V1
    【Alpha】最后一篇
    【Alpha】开发日志Day10-0721
  • 原文地址:https://www.cnblogs.com/lin277541/p/5074697.html
Copyright © 2011-2022 走看看