How to convert SWF to Image in ASP.NET using SWF To Video SDK - ByteScout

How to convert SWF to Image in ASP.NET using SWF To Video SDK

  • Home
  • /
  • Articles
  • /
  • How to convert SWF to Image in ASP.NET using SWF To Video SDK
SWF to Video SDK can be used to convert Flash to image files in ASP.NET (using Visual Basic .NET or Visual C# as programming language).
Remember that you should have Administrator access to the web-server to install the SDK.

The sample VB and C# codes below show how to convert SWF to PNG image in ASP.NET using SWF To Video SDK.

ASP.NET (Visual Basic)

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

ASP.NET (C#)

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();
        }
    }
}
Sample SWF to image conversion:

 

Input SWF video – shapes.swf Output PNG image file – result.png

Tutorials:

prev
next