ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rose_image.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_image
3 /// Display image in a new canvas and pad.
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Valeriy Onuchin
9 
10 #include "TImage.h"
11 #include "TCanvas.h"
12 #include "TArrayD.h"
13 #include "TROOT.h"
14 #include "TColor.h"
15 #include "TAttImage.h"
16 #include "TEnv.h"
17 
18 TCanvas *c1;
19 
20 void rose_image()
21 {
22  TImage *img = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
23 
24  if (!img) {
25  printf("Could not create an image... exit\n");
26  return;
27  }
28 
29  img->SetConstRatio(0);
31 
32  TString fp = gEnv->GetValue("Root.TTFontPath", "");
33  TString bc = fp + "/BlackChancery.ttf";
34  TString ar = fp + "/arial.ttf";
35 
36  // draw text over image with funny font
37  img->DrawText(120, 160, "Hello World!", 32,
38  gROOT->GetColor(4)->AsHexString(),
40 
41  // draw text over image with foreground specified by pixmap
42  img->DrawText(250, 350, "goodbye cruel world ...", 24, 0,
43  ar, TImage::kPlain, "fore.xpm");
44 
45  TImage *img2 = TImage::Open("mditestbg.xpm");
46 
47  // tile image
48  img2->Tile(img->GetWidth(), img->GetHeight());
49 
50  c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
51  c1->Divide(2, 3);
52  c1->cd(1);
53  img->Draw("xxx");
54  img->SetEditable(kTRUE);
55 
56  c1->cd(2);
57  // averaging with mditestbg.xpm image
58  TImage *img3 = (TImage*)img->Clone("img3");
59  img3->Merge(img2, "allanon");
60  img3->Draw();
61 
62  // contrasting (tint with itself)
63  c1->cd(3);
64  TImage *img4 = (TImage*)img->Clone("img4");
65  img4->Merge(img4, "tint");
66 
67  // draw filled rectangle with magenta color
68  img4->FillRectangle("#FF00FF", 20, 220, 40, 40);
69 
70  // Render multipoint alpha-blended gradient (R->G->B)
71  img4->Gradient(0, "#FF0000 #00FF00 #220000FF", 0, 50, 50, 100, 100);
72 
73  // draw semi-transparent 3D button
74  img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, 0);
75  img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
76  img4->Draw();
77 
78  // vectorize image. Reduce palette to 256 colors
79  c1->cd(4);
80  TImage *img5 = (TImage*)img->Clone("img5");
81  img5->Vectorize(256);
82  img5->Draw();
83 
84  // quantization of the image
85  c1->cd(5);
86  TImage *img6 = (TImage*)img->Clone("img6");
87  TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
88  TArrayD *arr = img6->GetArray(50, 40, pal);
89  img6->SetImage(arr->GetArray(), 50, 40, pal);
90  img6->Draw();
91 
92  // HSV adjustment (convert red to yellow)
93  c1->cd(6);
94  TImage *img7 = (TImage*)img->Clone("img7");
95  img7->HSV(0, 40, 40);
96  img7->Draw();
97 }
TCanvas * c1
Definition: legend1.C:2
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
Definition: TAttImage.cxx:641
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual Double_t * Vectorize(UInt_t=256, UInt_t=4, Int_t=0)
Definition: TImage.h:177
#define gROOT
Definition: TROOT.h:344
virtual UInt_t GetWidth() const
Definition: TImage.h:244
Basic string class.
Definition: TString.h:137
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
An abstract interface to image processing library.
Definition: TImage.h:45
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:188
virtual void SetImageQuality(EImageQuality lquality)
Definition: TAttImage.h:148
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:132
virtual void FillRectangle(const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:208
virtual void Bevel(Int_t=0, Int_t=0, UInt_t=0, UInt_t=0, const char *="#ffdddddd", const char *="#ff555555", UShort_t=1, Bool_t=kFALSE)
Definition: TImage.h:194
virtual UInt_t GetHeight() const
Definition: TImage.h:245
virtual const TImagePalette & GetPalette() const
Definition: TAttImage.h:137
virtual TObject * Clone(const char *) const
Make a clone of an object using the Streamer facility.
Definition: TImage.h:127
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual void SetEditable(Bool_t=kTRUE)
Definition: TImage.h:241
const Double_t * GetArray() const
Definition: TArrayD.h:45
The Canvas class.
Definition: TCanvas.h:48
virtual void DrawText(Int_t=0, Int_t=0, const char *="", Int_t=12, const char *=0, const char *="fixed", EText3DType=TImage::kPlain, const char *=0, Float_t=0)
Definition: TImage.h:216
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
virtual TArrayD * GetArray(UInt_t=0, UInt_t=0, TImagePalette *=gWebImagePalette)
Definition: TImage.h:250
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:83
Array of doubles (64 bits per element).
Definition: TArrayD.h:29
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition: TImage.h:200
virtual void Gradient(UInt_t=0, const char *="#FFFFFF #000000", const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:184
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:110
virtual void HSV(UInt_t=0, UInt_t=360, Int_t=0, Int_t=0, Int_t=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:180
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void Tile(UInt_t, UInt_t)
Definition: TImage.h:164