Discussions
Categories
- 385.5K All Categories
- 4.9K Data
- 2.5K Big Data Appliance
- 2.4K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
How to save 3D into a image file?
Hi guys:
I want to save a 3D image shown on the screen into a gif file, how could I do this?
regards.
I want to save a 3D image shown on the screen into a gif file, how could I do this?
regards.
Comments
-
I had the same problem. As far as i know, the paint method of the component which contains your Canvas3D object will only invoke the rendering process. Using this method to draw to an image will result in a black image.
A workaround i have found is to use the Robot API:
The following code writes the content of your Canvas3D in a JPEG file using the screenshot function.
I know it's a hack but it works on my machine...
'path' is the pathname of the destination jpeg file,
'canvas' is your Canvas3D object.
To use JPEGEncoder you have to import:
com.sun.image.codec.jpeg.*;
try
{
Robot robot = new Robot();
Rectangle theRectOnScreen = new Rectangle(canvas.getLocationOnScreen().x, canvas.getLocationOnScreen().y, canvas.getWidth(), canvas.getHeight());
BufferedImage bi = robot.createScreenCapture(theRectOnScreen);
File f = new File(path);
if (f.exists())
{
f.delete();
}
try
{
if (f.createNewFile())
{
FileOutputStream fos = new FileOutputStream(f);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
encoder.encode(bi);
fos.flush();
fos.close();
}
}
catch (IOException ioex)
{
System.out.println("Error writing JPEG");
}
}
catch (AWTException aex)
{
System.out.println("Error getting Screen content");
}
-
What is Robot? How to use the "Robot"?Thanks!
-
The java.awt.Robot can be used to generate native system input events (e.g. keyboard key pressed, mouse moved/pressed). You can use it for automatic testing or for demonstration purposes.
But as I've already said, this might be not the best solution. It simulates the printscreen key.
I recently found a link for this topic, see http://www.j3d.org/faq/capturing.html
I didn't try it out, perhaps this is the correct solution for our problem.
-
I went to the link and downloaded the CaptureCanvas3D.java file.
Ya so basically the postSwap method just gets called over and over by some thread running in the background. So when you want to draw the image to a file, you set the flag temporarily.
Seemed to work like a charm. Thanks for the link p_b! -
Thanks everybody here.
In fact, I want to get a image file by a backgroup thread without shown the picture on screeen, and I have tried CapturingCanvas3D, but the file will be created only after the cube was displayed, OH, my god, what can I do now?
-
Thanks everybody here.
In fact, I want to get a image file by a backgroup thread without shown the picture on screeen, and I have tried CapturingCanvas3D, but the file will be created only after the cube was displayed, OH, my god, what can I do now?
-
Try using a Canvas3D object in offscreen rendering mode.
(Second parameter -> true in Canvas3D constructor).
A Canvas3D in this mode can't be added to a container,
so there will nothing appear on the screen.
-
I had to try that. And it worked very well. Check out my site:
http://www.geocities.com/virtualexp
with the JPG-images I made.
Thanks for the info!
This discussion has been closed.