[vtkusers] How to take SreenShots

Somada141 somada141 at yahoo.gr
Fri Nov 28 08:00:01 EST 2008




Konstantinos Kelg wrote:
> 
> Does anyone know how to take screenshots from a vtk window (if possible)
> and save them i a file (raw/bmp/jpg/png/or whatever).
> 
> Thanks.
> 
> Hi, yes this is pretty standard stuff
> 
> Check out this code (Python):
> 
> 
> #!/usr/bin/env python
> 
> from vtk import *
> from random import random   
> 
> renderer = vtkRenderer()
> renderer_window = vtkRenderWindow()
> renderer_window.AddRenderer(renderer)
> renderer_interactor = vtkRenderWindowInteractor() 
> renderer_interactor.SetRenderWindow(renderer_window)
> renderer.SetBackground(0.8,0.8,0.8)
> renderer_window.SetSize(800, 600)
> 
> for x in range(3):
>     for y in range(3):
>         for z in range(3):
>             
>             a=random();b=random();c=random()
>                         
>             cube = vtkCubeSource()
>             cube.SetBounds(0,1,0,1,0,1)
>             
>             cubeMapper = vtkPolyDataMapper()            
>             cubeMapper.SetInputConnection(cube.GetOutputPort())
>                         
>             cubeActor = vtkActor()
>             cubeActor.SetMapper(cubeMapper)
>             cubeActor.SetPosition(x,y,z)
>             cubeActor.GetProperty().SetColor(a,b,c)
>             renderer.AddActor(cubeActor)
> 
> 
> renderer_interactor.Initialize()
> renderer_window.Render()
> renderer_interactor.Start()
> 
> #After rendering the image the window appears. The image showing before
> the user closes the windows is kept in the renderer
> renderLarge = vtkRenderLargeImage() #We use the 'vtkRenderLargeImage' to
> keep a snapshot of the image in the renderer
> renderLarge.SetInput(renderer)  #We define that the source is the renderer
> to get its picture
> renderLarge.SetMagnification(1) #BEWARE : By setting the magnification to
> 1 we make sure that the image's dimensions are those of the window
> 
> # We write out the image which causes the rendering to occur. If you
> # watch your screen you might see the pieces being rendered right
> # after one another.
> writer = vtkPNGWriter() #There are many 'Writers' for image types,
> bmp,tiff,jpeg,png e.t.c. However I chose png since this format has a great
> balance between size and quality
> writer.SetInputConnection(renderLarge.GetOutputPort())  #This is crucial.
> This is the connection between the renderer and the writer.
> writer.SetFileName("image.png") #We set the file name we want. This is an
> absolute path and the image is going to be saved next to the .py file
> writer.Write()  #And we save the file
> 
> 
> What I do here is render a 3x3x3 cube consisting of 27 cubes. The whole
> thing is rendered, the user changes perhaps the camera angle and as soon
> as the windows is closed the last thing you saw is saved as a png file
> 
> 
> 
> 
> 
>       
> ___________________________________________________________ 
> Χρησιμοποιείτε Yahoo!; 
> Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail 
> διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών 
> μηνυμάτων http://login.yahoo.com/config/mail?.intl=gr 
> 
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-take-SreenShots-tp20726736p20734014.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list