from System.IO import Path
from Spotfire.Dxp.Application.Visuals import VisualContent
#1. Prepare canvas as a blank bitmap
w=640
h=480
bm = Bitmap(w,h)
g = Graphics.FromImage(bm)
r = Rectangle(Point(0,0), bm.Size)
#2. Paint visualization into canvas
#vis is a script parameter
vis.As[VisualContent]().Render(g, r)
#3. Save your canvas
#tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName() + ".bmp"
bm.Save(tempFilename)
print "image saved as " + tempFilename
9 comments:
The font of the saved image differs from what's in dxp. How to set the image font?
how can I export the title of the visual?
Text, such as axis labels, comes out blurry. Any way to account for this or any other solutions to get visualizations out and maintain clean looking text?
Hello Scott,
You will need to play with the graphics settings to fine tune the output. Please share your findings!
Still can't get this to work on text areas. Anyone ever have any luck on that?
Figured it out, you need to turn on anti-aliasing.
Example below:
vc = crosstop.As[VisualContent]()
crosstop_r = Document.ActivePageReference.GetVisualBounds(crosstop)
bm = Bitmap(crosstop_r.Width, crosstop_r.Height)
crosstop_ratio = (float(crosstop_r.Width)/float(crosstop_r.Height))
g = Graphics.FromImage(bm)
g.TextRenderingHint = g.TextRenderingHint.AntiAlias
vc.Render(g, crosstop_r)
crosstopfile = Path.GetTempFileName()
bm.Save(crosstopfile, ImageFormat.Png)
@Trevor Hubbard - Do you declare ImageFormat earlier?
Took a minute to realize that I needed to import ImageFormat
from System.Drawing.Imaging import ImageFormat
Hey Blake + Trevor,
Enabling anti-aliasing didn't make a difference on my image outputs. My text is still bold/blurry. Do you have any other ideas?
Cheers,
Alex
Post a Comment