[vtkusers] problems creating image from GetRGBAPixelData

Christian schnabilo.chris at gmx.de
Tue May 11 05:48:20 EDT 2004


Hello vtkusers,
 
i have got a problem with the GetRGBAPixelData.
When i create a new image in a different frame using GetRGBAPixelData
and write the data into a bufferedimage under java, the newly created
image is somehow split and distorted, looking like its split in the
middle with the one half on the left and the other on the right. I
attached a small image to show the problem.
 
I also post my code below:
 
 
......
 
vtkActor aSphere = new vtkActor();
         aSphere.SetMapper(map);
         aSphere.GetProperty().SetColor(0,1,1); // color blue
         // a renderer for the data
         vtkRenderer ren1 = new vtkRenderer();
         ren1.AddActor(aSphere);
         ren1.SetBackground(1,1,1); // background color white
         // a render window to display the contents
         vtkRenderWindow renWin = new vtkRenderWindow();
         //renWin.SetDoubleBuffer(2);
         //renWin.SetSwapBuffers(0);
         renWin.AddRenderer(ren1);
         renWin.SetSize(500,500);
         //renWin.SetOffScreenRendering(0); 
         // an interactor to allow control of the objects
         vtkRenderWindowInteractor iren = new
vtkRenderWindowInteractor();
         iren.SetRenderWindow(renWin);
         // trigger the rendering and start the interaction
         renWin.Render();
         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++)
               {
                     for (int vColumn = 0; vColumn < pWidth; vColumn++)
                     {
                    // 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);
                   }
                  }
         Frame f = new Frame();
         f.setSize(new Dimension(500,500));
         f.setLocation(500, 10);
         f.setVisible(true);
}
...
 
Thank you for any help,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040511/f89a96ed/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pixeldataexample.jpg
Type: image/jpeg
Size: 8956 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040511/f89a96ed/attachment.jpg>


More information about the vtkusers mailing list