• Silverlight 控件截图与InkPresenter画笔


    控件截图

    控件截图关键是,System.Windows.Media.Imaging 空间下的 WriteableBitmap 对象

    using System.Windows.Media.Imaging;
    
    private void media_MouseLeftButtonDown(object sender
                , MouseButtonEventArgs e)
            {
                //创′建¨可é写′入?位?图?对?象ó,?尺?寸?根ù据YMediaElement的?实μ际ê大ó小?
                WriteableBitmap wBitmap = new WriteableBitmap(media.NaturalVideoWidth
                    , media.NaturalVideoHeight);
                //将?当±前°的?视ó频μ内ú容Y保£存?起e来′
                wBitmap.Render(media, new MatrixTransform());
                //创′建¨一?个?图?像?
                Image img = new Image();
                img.Width = 150;
                img.Margin = new Thickness(10);
                //将?wBitmap做?为a图?像?源′
                img.Source = wBitmap;
                //将?图?像?添í加ó到?WrapPanel控?件t
                //    wrap.Children.Add(img);
            }
    

    InkPresenter 画笔

    InkPresenter画笔,就是一个涂抹输入工具,通过鼠标或者绘画笔,写字啊,画图形,他就像是一个画板,可以在上面作画。
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Ink;
    
     
    //定¨义?一?个?画-笔ê对?象ó
            private Stroke myStroke;
            private void IP_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                //墨?迹£画-笔ê捕?获?鼠ó标ê
                IP.CaptureMouse();
                //创′建¨画-笔ê坐?标ê集ˉ合?SPC
                StylusPointCollection SPC = new StylusPointCollection();
                //将?当±前°IP对?象ó的?坐?标ê集ˉ合?添í加ó到?SPC
                SPC.Add(e.StylusDevice.GetStylusPoints(IP));
                //将?坐?标ê集ˉ合?添í加ó到?画-笔ê对?象ó
                myStroke = new Stroke(SPC);
                //墨?迹£的?尺?寸?
                myStroke.DrawingAttributes.Width = 10;
                myStroke.DrawingAttributes.Height = 10;
                //墨?迹£的?颜?色?
                myStroke.DrawingAttributes.Color = Colors.White;
                //将?画-笔ê对?象ó添í加ó到?IP的?画-笔ê集ˉ合?中D
                IP.Strokes.Add(myStroke);
            }
    
            private void IP_MouseMove(object sender, MouseEventArgs e)
            {
                if (myStroke != null)
                {
                    /* 当±鼠ó标ê移?动ˉ时±,?如?果?画-笔ê不?为a空?值μ就í继ì续?添í加ó
                    新?的?坐?标ê点?到?StylusPoints集ˉ合? */
                    myStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(IP));
                }
            }
    
            private void IP_LostMouseCapture(object sender, MouseEventArgs e)
            {
                //释í放?鼠ó标ê后ó将?画-笔ê置?为a空?值μ
                myStroke = null;
            }
    
     
     

    示例源自Silverlight 3 开发详解一书代码

    冯瑞涛
  • 相关阅读:
    有个名字叫随便乱记——css3
    CSS3伸缩布局
    路政整理
    GIst
    SVN回滚版本
    你需要知道的CSS3 动画技术
    iScroll框架的使用和修改
    CSS3阴影 box-shadow的使用和技巧总结
    Javascript异步编程的4种方法
    zepto学习零碎
  • 原文地址:https://www.cnblogs.com/finehappy/p/1669224.html
Copyright © 2020-2023  润新知