Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

c# - How to export a FusionChart to Image in ASP.Net

We are using the free version of fusion charts and want to know is there a way to export the generated chart to image without using any third party components. We are using the ASP.Net for generating the charts.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SOLUTION

After a research on this topic, I have found a useful solution for this.

For that we need to have a freeware from Bytecout to convert swf to image. This can be downloaded from this link.

Then we need to register the COM dlls and add the reference to our project. Refer to the below for further usage

Protected Sub btnSwf2ImgConverter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim swfobj As New SWFToImage.SWFToImageObject
    swfobj.InitLibrary("demo", "demo")
    swfobj.InputSWFFileName = Server.MapPath("dumps/swf/") & "FCF_MSColumn3D.swf"
    If ddlImageExtension.SelectedValue = "jpg" Then
        swfobj.ImageOutputType = TImageOutputType.iotJPG
        ext = ".jpg"
    Else
        If ddlImageExtension.SelectedValue = "gif" Then
            swfobj.ImageOutputType = TImageOutputType.iotGIF
            ext = ".gif"
        Else
            If ddlImageExtension.SelectedValue = "png" Then
                swfobj.ImageOutputType = TImageOutputType.iotPNG
                ext = ".png"
            Else
                If ddlImageExtension.SelectedValue = "bmp" Then
                    swfobj.ImageOutputType = TImageOutputType.iotBMP
                    ext = ".bmp"
                End If
            End If
        End If
    End If

    filenm = "FCF_Column3D" & ext
    swfobj.Execute_Begin()
    'swfobj.Execute()
    swfobj.Execute_SetVariable("dataXML", "<graph animation='0' formatNumber='1' divLineColor='ff5904' divLineAlpha='20' alternateHGridAlpha='5'  canvasBorderColor='666666'  baseFontColor='666666' showAlternateHGridColor='1' AlternateHGridColor='ff5904'  anchorSides='3' rotateNames='1' caption='Daily Reports' yAxisMinValue='0' yAxisMaxValue='1'  xAxisName='Day-Month-Year' yAxisName='Percentage' decimalPrecision='2'  numdivlines='8' numVdivlines='16' showhovercap='1'  formatNumberScale='0'> <categories> <category name='1-Jun-2010' showName='1' /> <category name='2-Jun-2010' showName='1' /> <category name='3-Jun-2010' showName='1' /> <category name='4-Jun-2010' showName='1' /> <category name='5-Jun-2010' showName='1' /> <category name='6-Jun-2010' showName='1' /> <category name='7-Jun-2010' showName='1' /> <category name='8-Jun-2010' showName='1' /> <category name='9-Jun-2010' showName='1' /> <category name='10-Jun-2010' showName='1' /> <category name='11-Jun-2010' showName='1' /> <category name='12-Jun-2010' showName='1' /> <category name='13-Jun-2010' showName='1' /> <category name='14-Jun-2010' showName='1' /> <category name='15-Jun-2010' showName='1' /> <category name='Aggregate' showName='1' /></categories><dataset  showValues='0' alpha='80' showAnchors='1' seriesname='Answered Percent' color='#f07979' lineThickness='2'><set name='Month' value='97.6'/><set name='Month' value='98.2'/><set name='Month' value='99.3'/><set name='Month' value='99.6'/><set name='Month' value='95.2'/><set name='Month' value='99.3'/><set name='Month' value='99.3'/><set name='Month' value='98.8'/><set name='Month' value='97.5'/><set name='Month' value='96.3'/><set name='Month' value='98.6'/><set name='Month' value='99.1'/><set name='Month' value='99.3'/><set name='Month' value='99.6'/><set name='Month' value='99.2'/><set name='Month' value='98.38'/></dataset></graph>")
    swfobj.Execute_SetVariable("chartWidth", "750")
    swfobj.Execute_SetVariable("chartHeight", "600")
    swfobj.ImageWidth = 600
    swfobj.ImageHeight = 500
    Threading.Thread.Sleep(10000)

    swfobj.Execute_GetImage()
    swfobj.SaveToFile(Server.MapPath("dumps/images/" & filenm))
    swfobj.Execute_End()
    Call DownloadImage(filenm)
End Sub

Public Sub DownloadImage(ByVal fn As String)
    Image1.ImageUrl = "~/dumps/images/" & fn
    Dim fi As New FileInfo(Server.MapPath("dumps/images/" & fn))
    HttpContext.Current.Response.Clear()
    HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fn))
    HttpContext.Current.Response.ContentType = "image/" & DropDownList1.SelectedValue
    Response.WriteFile(fi.FullName)
    Response.Flush()
    fi.Delete()
    Response.End()

End Sub

Here animation='0' plays a very important role, it specifies the fusion chart swf that, it must be loaded without animation. Also it is advisable if we sleep the code for 1 or 2 sec the swf would be loaded completely and image is converted to the selected format.

Hope this would be useful for someone like me. :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...