Home | News | Documentation | Download

Saving a PNG file creates an EPS

I’m not sure when ROOT started supporting saving a canvas as PNG file.
Here at CDF the version of ROOT we use is the following one:
Version 4.00/08 1 December 2004
CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004

If I do canvas->Print("image.png", "png"); and then try to open the image in the web browser, I get “The image “file:///home/joe_user/image.png” cannot be displayed, because it contains errors.” If opent the image in a text editor – it looks like a usual EPS. Is it my version of ROOT that’s too old, or is there something fishy going on?

Three more comments:

  1. I did not know about TImage class when I posted the above (There’s nothing in the description of TPad::Print(…) that suggests to look at TImage)

  2. going through tutorials I found this recipe:

TImage *img = TImage::Create();
 img->FromPad(c);
 img->WriteImage("canvas.png");

It does not work in batch mode (and I need to save the image in batch mode). It spits out this: Error in TASImage::WriteImage: no image loaded

  1. it work in the intercative mode, but the image it saves is visually different from the EPS (e.g., some axis labels that were suppresed in EPS are visible in PNG)

[quote=“cyberkost”]I’m not sure when ROOT started supporting saving a canvas as PNG file.
Here at CDF the version of ROOT we use is the following one:
Version 4.00/08 1 December 2004
CINT/ROOT C/C++ Interpreter version 5.15.138, May 23 2004

If I do canvas->Print("image.png", "png"); and then try to open the image in the web browser, I get “The image “file:///home/joe_user/image.png” cannot be displayed, because it contains errors.” If opent the image in a text editor – it looks like a usual EPS. Is it my version of ROOT that’s too old, or is there something fishy going on?[/quote]

PNG (gif, jpeg etc…) generation in batch mode is working in ROOT since release 5.06. The ROOT version you are using is too old.

1 Like