Print at Dec 15, 2025, 6:39:36 PM View all posts in this thread on one page
Posted by javivf at Nov 2, 2010, 3:51:07 PM
Getting a PNG Photo Image
Hi there,

I'm trying to save a png image with this code but not works :


HomeComponent3D homeComponent3D = new HomeComponent3D(getHome());
int imageWidth = 400;
int imageHeight = 400;
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
image = homeComponent3D.getOffScreenImage(imageWidth, imageHeight);
File file = new File("tmp.png");
ImageIO.write(image, "png", file);


Anybody can tell me what i'm doing wrong?

Thanks.

Posted by Puybaret at Nov 2, 2010, 5:40:22 PM
Re: Getting a PNG Photo Image
I just tried your code and it worked as expected (under Mac OS X). You don't need to create the BufferedImage instance, and you can call create getOffScreenImage directly, as shown in this test case:

public class Export3DViewToPNG {
public static void main(String [] args) throws RecorderException, IOException {
Home home = new HomeFileRecorder().readHome("test.sh3d");
HomeComponent3D homeComponent3D = new HomeComponent3D(home);
BufferedImage image = homeComponent3D.getOffScreenImage(400, 400);
File file = new File("tmp.png");
ImageIO.write(image, "png", file);
}
}

Under which system do you work?
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by Puybaret at Nov 2, 2010, 5:53:44 PM
Re: Getting a PNG Photo Image
I checked under Windows and Linux and it worked too.
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D creator

Posted by javivf at Nov 2, 2010, 10:09:42 PM
Re: Getting a PNG Photo Image
I just tried your code and it worked as expected (under Mac OS X). You don't need to create the BufferedImage instance, and you can call create getOffScreenImage directly


True, it works fine. It was a permissions problem with windows vista. Thanks for tip, i'm just a java newbie. I hope this changes in the future :)