The sample VB and C# codes below show how to convert SWF to PNG image in ASP.NET using SWF To Video SDK.
Imports System.IO Imports BytescoutSWFToVideo Public Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) Dim inputSwfFile As String = Server.MapPath("Shapes.swf") ' Create an instance of SWFToVideo ActiveX object Dim converter As New SWFToVideo() ' Set debug log 'converter.SetLogFile("log.txt"); ' Register SWFToVideo converter.RegistrationName = "demo" converter.RegistrationKey = "demo" ' Enable trasparency - set BEFORE calling input SWF filename converter.RGBAMode = True ' Set input SWF file converter.InputSWFFileName = inputSwfFile ' Select the frame to extract (20th) converter.StartFrame = 20 converter.StopFrame = 20 ' Run conversion. ' Empty parameter means conversion to binary stream instead of file. converter.ConvertToPNG("") ' Display the extracted image: Response.Clear() ' Add content type header Response.ContentType = "image/png" ' Set the content disposition Response.AddHeader("Content-Disposition", "inline;filename=result.png") ' Write the image bytes into the Response output stream Response.BinaryWrite(DirectCast(converter.BinaryImage, Byte())) Response.End() End Sub End Class
using System; using System.IO; using BytescoutSWFToVideo; namespace SwfToPng { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { String inputSwfFile = Server.MapPath("Shapes.swf"); // Create an instance of SWFToVideo ActiveX object SWFToVideo converter = new SWFToVideo(); // Set debug log //converter.SetLogFile("log.txt"); // Register SWFToVideo converter.RegistrationName = "demo"; converter.RegistrationKey = "demo"; // Enable trasparency - set BEFORE setting SWF filename converter.RGBAMode = true; // set input SWF file converter.InputSWFFileName = inputSwfFile; // Select the frame to extract (20th) converter.StartFrame = 20; converter.StopFrame = 20; // Run conversion. // Empty parameter means conversion to binary stream instead of file. converter.ConvertToPNG(""); // Display the extracted image: Response.Clear(); // Add content type header Response.ContentType = "image/png"; // Set the content disposition Response.AddHeader("Content-Disposition", "inline;filename=result.png"); // Write the image bytes into the Response output stream Response.BinaryWrite((byte[]) converter.BinaryImage); Response.End(); } } }
Input SWF video – shapes.swf | Output PNG image file – result.png |