Exemplo n.º 1
0
 /// <summary>
 /// 保存图片
 /// </summary>
 /// <returns></returns>
 public BitmapSource Save()
 {
     if (GlobalBorder != null)
     {
         double left = GlobalBorder.Margin.Left;
         double top  = GlobalBorder.Margin.Top;
         System.Drawing.Image    CatchedBmp = new System.Drawing.Bitmap((int)GlobalBorder.Width, (int)GlobalBorder.Height);
         System.Drawing.Graphics g          = System.Drawing.Graphics.FromImage(CatchedBmp); //创建图片画布
         ////目标范围
         System.Drawing.Rectangle desiRectangle = new System.Drawing.Rectangle(0, 0, (int)GlobalBorder.Width, (int)GlobalBorder.Height);
         ////源范围
         System.Drawing.Rectangle sourceRectangle = new System.Drawing.Rectangle((int)left, (int)top, (int)GlobalBorder.Width, (int)GlobalBorder.Height);
         g.DrawImage(GlobalBitmap, desiRectangle, sourceRectangle, System.Drawing.GraphicsUnit.Pixel);
         //保存到剪贴板
         System.Drawing.Bitmap map    = (System.Drawing.Bitmap)CatchedBmp;
         BitmapSource          source = ScreenCaptureHelper.ToBitmapSource(map);
         g.Dispose();
         CatchedBmp.Dispose();
         this.Close();
         return(source);
     }
     return(null);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 窗体回调函数,接收所有窗体消息的事件处理函数,在这里设置快捷键操作
        /// </summary>
        /// <param name="hWnd">窗口句柄</param>
        /// <param name="msg">消息</param>
        /// <param name="wideParam">附加参数1</param>
        /// <param name="longParam">附加参数2</param>
        /// <param name="handled">是否处理</param>
        /// <returns>返回句柄</returns>
        private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wideParam, IntPtr longParam, ref bool handled)
        {
            //var hotkeySetting = new EHotKeySetting();
            switch (msg)
            {
            case HotKeyManager.WM_HOTKEY:
                int sid = wideParam.ToInt32();
                //if (sid == m_HotKeySettings[EHotKeySetting.全屏])
                //{
                //    hotkeySetting = EHotKeySetting.全屏;
                //    //TODO 执行全屏操作
                //}
                //else
                if (App.Current.Windows.Cast <Window>().Any(x => x is PrintScreen))
                {
                    break;                                                                     //查看是否存在Window7窗口正在运行
                }
                if (sid == m_HotKeySettings[EHotKeySetting.截图])
                {
                    //hotkeySetting = EHotKeySetting.截图;
                    DateTime    dt          = DateTime.Now;
                    Bitmap      bitMap      = ScreenCaptureHelper.GetScreenSnapshot();
                    BitmapImage bitmapImage = ScreenCaptureHelper.BitmapToBitmapImage(bitMap);
                    //BitmapImage skinBitmap = ScreenCaptureHelper.BitmapToBitmapImage(SkinBitmap);
                    PrintScreen win7 = new PrintScreen(bitmapImage, bitMap);
                    win7.ShowDialog();

                    //ImageSource img = System.Windows.Clipboard.GetImage();
                }
                //else if (sid == m_HotKeySettings[EHotKeySetting.播放])
                //{
                //    hotkeySetting = EHotKeySetting.播放;
                //    //TODO ......
                //}
                //else if (sid == m_HotKeySettings[EHotKeySetting.前进])
                //{
                //    hotkeySetting = EHotKeySetting.前进;
                //}
                //else if (sid == m_HotKeySettings[EHotKeySetting.后退])
                //{
                //    hotkeySetting = EHotKeySetting.后退;
                //}
                //else if (sid == m_HotKeySettings[EHotKeySetting.保存])
                //{
                //    hotkeySetting = EHotKeySetting.保存;
                //}
                //else if (sid == m_HotKeySettings[EHotKeySetting.打开])
                //{
                //    hotkeySetting = EHotKeySetting.打开;
                //}
                //else if (sid == m_HotKeySettings[EHotKeySetting.新建])
                //{
                //    hotkeySetting = EHotKeySetting.新建;
                //}
                //else if (sid == m_HotKeySettings[EHotKeySetting.删除])
                //{
                //    hotkeySetting = EHotKeySetting.删除;
                //}
                //MessageBox.Show(string.Format("触发【{0}】快捷键", hotkeySetting));
                handled = true;
                break;
            }
            return(IntPtr.Zero);
        }