[vtkusers] vtkCanvas to Java image

R K Shyam Prakash ramakrishna.prakash at quest-global.com
Wed Jun 23 10:10:49 EDT 2004


Biele,
	I am not sure if it works. I found it in the archives.


	   vtkFloatArray buffer = new vtkFloatArray();
	   
	   renWin.GetRGBAPixelData(0, 0, 500, 500, 1, buffer);
	   
	   //for(int i=0; i<500*500; i++)
	     // System.out.println("byte:"+buffer.GetValue(i));
	   //System.out.println(buffer.GetSize()); 
	    
		int pWidth=500;
		int pHeight=500;
	    
		BufferedImage vBufferedImage = new BufferedImage(pWidth,
pHeight, BufferedImage.TYPE_INT_RGB);
         
        //Copy pixel data into buffered image
		   for (int vRow = 0; vRow < pHeight; vRow+=1)
		   {
			   for (int vColumn = 0; vColumn < pWidth;
vColumn+=1)
			   {
			  // Get separate color components
			  int vIndex = ((vRow * pWidth) + vColumn)*4;
			  int r = (int) (buffer.GetValue(vIndex) * 255);
			  int g = (int) (buffer.GetValue(vIndex + 1) *
255);
			  int b = (int) (buffer.GetValue(vIndex + 2) *
255);
			  /*
			  * Set rgb color by shifting components into
corresponding
			  * integer bits.
			  */
			  int vRgb = (r << 16) + (g << 8) + b;
 			  //Set buffer image pixel -- flip y coordinate
			  
			  vBufferedImage.setRGB(
			  vColumn,
			  vRow,
			  vRgb);
			 }
			}

--Shyam	

> -----Original Message-----
> From: vtkusers-bounces at vtk.org 
> [mailto:vtkusers-bounces at vtk.org] On Behalf Of Biele
> Sent: Wednesday, June 23, 2004 1:55 PM
> To: vtkusers at vtk.org
> Subject: Re: [vtkusers] vtkCanvas to Java image
> 
> 
> > Have you looked at vtk*Writer under the IO/ directory? [...]
> 
> Thanks Tom, that's a possibility.
> But I really would prefer to get a BufferedImage (or read the 
> pixel data to create one myself) and use the Java export 
> methods for consistency reasons with other program parts. Is 
> there a way?
> 
> 
> >  <026101c458a7$4e1554a0$0306a8c0 at bierle>"Biele" writes:
> > >Hi,
> > >
> > >I have a 3D-graphic Java application using vtk. Now I want 
> to export 
> > >images/movies to formats like .jpg, .avi etc. The Java Media 
> > >Framework (JMF) allows me to export like that but I need a 
> Java image 
> > >like "java.awt.image.BufferedImage". Does anybody know a 
> way to get 
> > >the picture from the vtkCanvas to a BufferedImage?
> > >If not, can I access the pixel data of the rendered image 
> from my Java
> > >application?
> > >Or export a file (i.e. jpg) directly from vtk?
> > >
> > >Thanks for any ideas,
> > >
> > >Biele
> 
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: 
<http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list