Logo ROOT  
Reference Guide
psview.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// An example how to display PS, EPS, PDF files in canvas.
5/// To load a PS file in a TCanvas, the ghostscript program needs to be install.
6/// - On most unix systems it is installed by default.
7/// - On Windows it has to be installed from http://pages.cs.wisc.edu/~ghost/
8/// also the place where gswin32c.exe sits should be added in the PATH. One
9/// way to do it is:
10/// 1. Start the Control Panel
11/// 2. Double click on System
12/// 3, Open the "Advanced" tab
13/// 4. Click on the "Environment Variables" button
14/// 5. Find "Path" in "System variable list", click on it.
15/// 6. Click on the "Edit" button.
16/// 7. In the "Variable value" field add the path of gswin32c
17/// (after a ";") it should be something like:
18/// "C:\Program Files\gs\gs8.13\bin"
19/// 8. click "OK" as much as needed.
20///
21/// \macro_code
22///
23/// \author Valeriy Onoutchin
24
25#include "TROOT.h"
26#include "TCanvas.h"
27#include "TImage.h"
28
29void psview()
30{
31 // set to batch mode -> do not display graphics
32 gROOT->SetBatch(1);
33
34 // create a PostScript file
35 TString dir = gROOT->GetTutorialDir();
36 dir.Append("/graphics/feynman.C");
37 gROOT->Macro(dir);
38 gPad->Print("feynman.eps");
39
40 // back to graphics mode
41 gROOT->SetBatch(0);
42
43 // create an image from PS file
44 TImage *ps = TImage::Open("feynman.eps");
45
46 if (!ps) {
47 printf("GhostScript (gs) program must be installed\n");
48 return;
49 }
50
51 new TCanvas("psexam", "Example how to display PS file in canvas", 600, 400);
52 TLatex *tex = new TLatex(0.06,0.9,"The picture below has been loaded from a PS file:");
53 tex->Draw();
54
55 TPad *eps = new TPad("eps", "eps", 0., 0., 1., 0.75);
56 eps->Draw();
57 eps->cd();
58 ps->Draw("xxx");
59}
#define gROOT
Definition: TROOT.h:406
#define gPad
Definition: TVirtualPad.h:287
The Canvas class.
Definition: TCanvas.h:27
An abstract interface to image processing library.
Definition: TImage.h:29
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:119
To draw Mathematical Formula.
Definition: TLatex.h:18
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
The most important graphics class in the ROOT system.
Definition: TPad.h:29
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1284
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:593
Basic string class.
Definition: TString.h:131
TString & Append(const char *cs)
Definition: TString.h:559
static constexpr double ps