Click here to Skip to main content
15,889,034 members
Articles / Web Development / ASP.NET
Article

Convert SWF movie to Image [.jpg, .gif, .png, .bmp]

Rate me:
Please Sign up or sign in to vote.
2.27/5 (6 votes)
15 Jan 2008CPOL1 min read 83.9K   3.7K   21   15
Convert your swf movie file to image
Image 1

Introduction

This piece of code will help you to generate images from your flash movie files[.swf].

Background

Sometime it's very important to get the screen shot of the first frame of .swf files. These things needs mostly whenever you work with ActiveX component like flash with ASP.Net. This program will extract the very first frame of the flash movie file and will save it as popular image formats like .jpg, .gif, .png, .bmp on the fly.

Using the code

Using the code is very simple but before that you have to setup some basic things. In this application I have used Interop.SWFToImage.dll to convert the swf files.

So at first download SWFToImage.exe from http://www.bytescout.com . This is a free product. Just download it and install the .exe file.

Your set up is ready to execute the application. Now add a reference of the Interop dll. The dll will be found within the installation directory, in the "Redistributable" folder.

Now import the SWFToImage class and create an object of it. Rest is easy. Here are some important code snippet.

swfobj.InputSWFFileName = FileUpload1.PostedFile.FileName
swfobj.ImageOutputType = TImageOutputType.iotJPG
swfobj.Execute()
swfobj.SaveToFile(Server.MapPath("dumps/images/" & filenm))        

Here swfobject is the object of the SWFToImage class. The property ImageOutputType receives the format of the converted image[.jpg, .gif, .png, .bmp].

According to the folder structure the uploaded files will be stored in the "dumps/swf" and the converted images will be stored in the "dump/images" folder.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionsource Pin
HosseinRabiee9-Aug-11 20:10
HosseinRabiee9-Aug-11 20:10 
GeneralI got the solution Pin
aaa200927-Oct-10 6:59
aaa200927-Oct-10 6:59 
GeneralBlack sreen is being captured as the image Pin
aaa200927-Oct-10 4:28
aaa200927-Oct-10 4:28 
QuestionMay you please give me any advice to convert big swf files like 200MB, 900MB and more to images? Pin
aaa200927-Oct-10 3:33
aaa200927-Oct-10 3:33 
GeneralAlignment problem Pin
shailendra118711-Feb-10 23:33
shailendra118711-Feb-10 23:33 
GeneralRe: Alignment problem Pin
aaa200927-Oct-10 4:31
aaa200927-Oct-10 4:31 
QuestionWhite output image Pin
ronnyvdbempt3-Aug-09 5:42
ronnyvdbempt3-Aug-09 5:42 
AnswerRe: White output image Pin
aaa200927-Oct-10 4:38
aaa200927-Oct-10 4:38 
AnswerRe: White output image Pin
aaa200927-Oct-10 7:00
aaa200927-Oct-10 7:00 
Hello,

I got the solution to the problem where only a black image is being displayed after being converted from the swf file.

I did add the line "swfobj.FrameIndex = 100" after each extension declaration in the code. The total code is as below:-

-------------------------------------------------------------------------------------------
Imports SWFToImage
Imports System.IO

Partial Class _Default
Inherits System.Web.UI.Page

Dim ext, filenm As String

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim swfobj As New SWFToImage.SWFToImageObject

Dim fl As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)

swfobj.InputSWFFileName = FileUpload1.PostedFile.FileName


Dim path As String = Server.MapPath("dumps/swf/")

FileUpload1.PostedFile.SaveAs(path & fl)

If DropDownList1.SelectedValue = "jpg" Then
swfobj.ImageOutputType = TImageOutputType.iotJPG
ext = ".jpg"
swfobj.FrameIndex = 100
Else
If DropDownList1.SelectedValue = "gif" Then
swfobj.ImageOutputType = TImageOutputType.iotGIF
ext = ".gif"
swfobj.FrameIndex = 100
Else
If DropDownList1.SelectedValue = "png" Then
swfobj.ImageOutputType = TImageOutputType.iotPNG
ext = ".png"
swfobj.FrameIndex = 100
Else
If DropDownList1.SelectedValue = "bmp" Then
swfobj.ImageOutputType = TImageOutputType.iotBMP
ext = ".bmp"
swfobj.FrameIndex = 100
End If
End If
End If
End If

filenm = fl.Substring(0, fl.LastIndexOf(".")) & ext
swfobj.Execute()
swfobj.SaveToFile(Server.MapPath("dumps/images/" & filenm))

Call display(filenm)
End Sub

Public Sub display(ByVal fn As String)
Image1.ImageUrl = "~/dumps/images/" & fn
End Sub

End Class

-------------------------------------------------------------------------------------------

Conclusion: As before, without the frameindex, the dll was fetching the frame with the index of 0(First index). Actually, video files consist of a lot of frames and usually, some black or white or some other "not related to the actual video" are displayed at the start time of any type of video and as the frames are very small in their size, so I did mention to the frame which is with the index of 100. Because, almost no videos will contain "not related to the actual video" contents at this index, so the actual image of the video will be created.
GeneralRe: White output image Pin
mogi_102025-Dec-13 16:50
mogi_102025-Dec-13 16:50 
General[Message Deleted] Pin
ronnyvdbempt2-Aug-09 22:28
ronnyvdbempt2-Aug-09 22:28 
QuestionWhere to find SWFToImage.exe Pin
suresh Naidu.K11-Feb-09 22:08
suresh Naidu.K11-Feb-09 22:08 
AnswerRe: Where to find SWFToImage.exe Pin
arinhere11-Feb-09 22:11
arinhere11-Feb-09 22:11 
GeneralMy vote of 1 Pin
cagriarican21-Jan-09 5:25
cagriarican21-Jan-09 5:25 
GeneralRe: My vote of 1 Pin
ytzipp4-Mar-09 16:29
ytzipp4-Mar-09 16:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.