Getting a PNG Photo Image

This topic has been viewed 5052 times and has 3 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
User avatar
javivf
Posts: 6
Joined: Sun Mar 21, 2010 5:15 pm
Contact:

Getting a PNG Photo Image

Post by javivf »

Hi there,

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

Code: Select all

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.
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Getting a PNG Photo Image

Post by Puybaret »

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:

Code: Select all

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
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Getting a PNG Photo Image

Post by Puybaret »

I checked under Windows and Linux and it worked too.
Emmanuel Puybaret, Sweet Home 3D creator
User avatar
javivf
Posts: 6
Joined: Sun Mar 21, 2010 5:15 pm
Contact:

Re: Getting a PNG Photo Image

Post by javivf »

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 :)
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest