Пример #1
0
        ///<summary>
        ///flash截取图片操作
        /// </summary>
        public static string SaveFlashImage(AxShockwaveFlash control)
        {
            var flashW = control.Width;

            var      flashH      = control.Height;
            string   flashPath   = "";
            string   flashFormat = "";
            FileInfo finfo       = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + @"\XML\" + "Screen.xml");

            if (finfo.Exists)
            {
                //System.Windows.MessageBox.Show(flashPath + "");
                //读取XML文档信息
                XmlDocument flashXml = new XmlDocument();
                //从指定的Url加载xml文档
                flashXml.Load(AppDomain.CurrentDomain.BaseDirectory + @"\XML\" + "Screen.xml");
                //找出xml中的Screen.xml中的Screen单个节点
                XmlNode flashNode = flashXml.SelectSingleNode("Screen");
                //获取根节点信息
                XmlElement flashElement = (XmlElement)flashNode;
                //获取保存图片位置
                flashPath = flashElement["Location"].InnerText + "\\";
                //获取保存图片格式
                //System.Windows.Forms.MessageBox.Show(flashPath+"");
                flashFormat = flashElement["Format"].InnerText;
            }
            if (string.IsNullOrEmpty(flashPath))
            {
                flashPath = "C:\\";
            }
            if (string.IsNullOrEmpty(flashFormat))
            {
                flashFormat = ".bmp";
            }
            //GUID(全局统一标识符)
            string   reValue = string.Format("{0}{1}" + flashFormat + "", flashPath, Guid.NewGuid().ToString());
            Graphics g0fCtrl = control.CreateGraphics();
            var      bmp     = new Bitmap(flashW, flashH, g0fCtrl);
            Graphics g0fBbmp = Graphics.FromImage(bmp);
            IntPtr   dc1     = g0fCtrl.GetHdc();
            IntPtr   dc2     = g0fBbmp.GetHdc();

            BitBlt(dc2, 0, 0, flashW, flashH, dc1, 0, 0, SRCCOPY);
            g0fCtrl.ReleaseHdc(dc1);
            g0fBbmp.ReleaseHdc(dc2);
            g0fCtrl.Dispose();
            g0fBbmp.Dispose();
            bmp.Save(reValue);
            return(reValue);
        }