Jump to content
  • How to export a visualization as an image in Spotfire® using IronPython scripting


    A sample script for exporting a visualization as an image

    Introduction 

    A sample script for exporting a visualization as an image.

    Code Sample

    Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    #visual is a script input parameter that needs to be added to reference 
    #the visualization being exported as an image
    
    import System
    from System.Drawing import Bitmap, Rectangle
    from System.Drawing import Graphics, Image
    from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread 
    
    app = Application.GetService(ApplicationThread)
    image = Bitmap(800, 600)
    
    def f(visual=visual, document=Document, app=app, image=image, Graphics=Graphics, Rectangle=Rectangle):
    
    	try:
    		vis = visual
    		gfx = Graphics.FromImage(image)
    		rect = Rectangle(0,0,image.Width,image.Height)
    		visualBounds = document.ActivePageReference.GetVisualBounds(vis, rect)
    		vis.Render(gfx, visualBounds)
    	except:
    		return
    	# DO SOMETHING WITH THE IMAGE HERE
    	image.Save(r'C:Tempimage.bmp')
    app.InvokeAsynchronously(f)
     

    See also

    References

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...