public static Image StaticTakeScreenshot(String MovieURL, Size Size, int FrameNum = 0, FlashScaleMode ScaleMode = FlashScaleMode.showAll, Color? BackgroundColor = null) { var flash = new ExAxShockwaveFlash(); //IFormatter formatter = new BinaryFormatter(); //var state = (AxHost.State)formatter.Deserialize(new MemoryStream(OcxData)); //Console.WriteLine(state); if (!File.Exists(MovieURL)) throw(new Exception("Flash Movie '" + MovieURL + "' doesn't exists.")); String Hash = "ExAxShockwaveFlashCache_" + MD5Hex(MovieURL) + "_" + MD5Hex(File.GetLastWriteTimeUtc(MovieURL).ToString()) + "_" + Size.Width + "x" + Size.Height + "_" + FrameNum + "_" + ScaleMode + "_" + MD5Hex(BackgroundColor.ToString()); String CacheTempFile = Path.GetTempPath() + @"\" + Hash + ".bmp"; if (File.Exists(CacheTempFile)) { return Image.FromFile(CacheTempFile); } var tempForm = new Form(); tempForm.BackColor = Color.White; flash.BeginInit(); { tempForm.Controls.Add(flash); flash.Size = Size; //flash.Visible = false; } flash.EndInit(); //flash.PreferredSize = Size; flash.LoadMovie(0, MovieURL); flash.Size = Size; flash.Quality = 1; flash.GotoFrame(FrameNum); flash.ScaleMode = (int)ScaleMode; //flash.BGColor = "ffffff"; if (BackgroundColor.HasValue) { //Console.WriteLine(BackgroundColor); //Console.WriteLine(BackgroundColor.Value.R); //flash.BGColor = "ffffff"; //flash.WMode = "Window"; //flash.BackColor = Color.White; //flash.BackgroundColor = BackgroundColor.Value.ToArgb(); flash.BackgroundColor = (BackgroundColor.Value.R << 0) | (BackgroundColor.Value.G << 8) | (BackgroundColor.Value.B << 16); } else { flash.WMode = "Transparent"; //Console.WriteLine("Transparent"); } //Thread.Sleep(20); Bitmap Screenshot = flash.TakeScreenshot(Size); flash.Dispose(); tempForm.Dispose(); Screenshot.Save(CacheTempFile); return Screenshot; }
/// C:\Windows\SysWOW64\Macromed\Flash void ExecuteFlash() { if (args.Length < 1) { Console.WriteLine("as3exec <file.swf>"); ShouldExit = true; return; //throw (new Exception("Exiting")); //Application.ExitThread(); //Application.Exit(); //return; } var ocxNames = new string[] { "Flash11a.ocx", "Flash10u.ocx", "Flash.ocx" }; String OcxPathBase = Directory.GetParent(Application.ExecutablePath).FullName; foreach (var ocxName in ocxNames) { String ocxPath = String.Format(@"{0}\{1}", OcxPathBase, ocxName); if (File.Exists(ocxPath)) { flash = new ExAxShockwaveFlash(ocxPath); break; } } if (flash == null) { flash = new ExAxShockwaveFlash(); } flash.BeginInit(); { //flash.Size = Size; flash.Size = new Size(1, 1); //flash.Visible = false; this.Controls.Add(flash); } flash.EndInit(); //flash.PreferredSize = Size; //flash.SetVariable("Arguments", flash.SerializeObject(args)); flash.RegisterCallback("getargs" , as3_getargs); flash.RegisterCallback("writef" , as3_writef); flash.RegisterCallback("writefln", as3_writefln); flash.RegisterCallback("fs_write", as3_fs_write); flash.RegisterCallback("fs_read", as3_fs_read); flash.RegisterCallback("fs_exists", as3_fs_exists); flash.RegisterCallback("fs_delete", as3_fs_delete); flash.RegisterCallback("fs_list", as3_fs_list); flash.RegisterCallback("fs_stat", as3_fs_stat); flash.RegisterCallback("fs_mkdir", as3_fs_mkdir); flash.RegisterCallback("fs_watch", as3_fs_watch); flash.RegisterCallback("fs_unwatch", as3_fs_unwatch); flash.RegisterCallback("exit" , as3_exit); //Console.WriteLine(ExAxShockwaveFlash.ToJson(args)); //args = new string[] { @"D:\OurClientV2\src\UnitTests\bin\UnitTests.swf" }; var MoviePath = Path.GetFullPath(args[0]); if (!File.Exists(MoviePath)) throw(new Exception(String.Format("File '{0}' doesn't exist", MoviePath))); flash.Movie = MoviePath; //flash.LoadMovie(0, MoviePath); try { //flash.Size = Size; flash.Quality = 1; flash.GotoFrame(0); flash.Play(); if (flash.TotalFrames == 0) { throw(new Exception("")); } } catch (Exception Exception) { throw (new Exception(String.Format("Can't load movie '{0}'", MoviePath), Exception)); } Controls.Add(flash); //Console.WriteLine(flash.Playing); //flash.ScaleMode = (int)ScaleMode; //flash.LoadMovie(0, ); //ExternalInterfaceCall //Console.WriteLine(flash); }