Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rose_image.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_image
3 /// \notebook
4 /// Display image in a new canvas and pad.
5 ///
6 /// \macro_image
7 /// \macro_code
8 ///
9 /// \author Valeriy Onuchin
10 
11 #include "TImage.h"
12 #include "TCanvas.h"
13 #include "TArrayD.h"
14 #include "TROOT.h"
15 #include "TColor.h"
16 #include "TAttImage.h"
17 #include "TEnv.h"
18 
19 TCanvas *c1;
20 
21 void rose_image()
22 {
23  TString dir = TROOT::GetTutorialDir();
24 
25  TImage *img = TImage::Open(dir + "/image/rose512.jpg");
26 
27  if (!img) {
28  printf("Could not create an image... exit\n");
29  return;
30  }
31 
32  img->SetConstRatio(0);
33  img->SetImageQuality(TAttImage::kImgBest);
34 
35  TString bc = "BlackChancery.ttf";
36  TString ar = "arial.ttf";
37 
38  // draw text over image with funny font
39  img->DrawText(120, 160, "Hello World!", 32,
40  gROOT->GetColor(4)->AsHexString(),
41  bc, TImage::kShadeBelow);
42 
43  // draw text over image with foreground specified by pixmap
44  img->DrawText(250, 350, "goodbye cruel world ...", 24, 0,
45  ar, TImage::kPlain, dir + "/image/fore.xpm");
46 
47  TImage *img2 = TImage::Open(dir + "/image/mditestbg.xpm");
48 
49  // tile image
50  img2->Tile(img->GetWidth(), img->GetHeight());
51 
52  c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
53  c1->Divide(2, 3);
54  c1->cd(1);
55  img->Draw("xxx");
56  img->SetEditable(kTRUE);
57 
58  c1->cd(2);
59  // averaging with mditestbg.xpm image
60  TImage *img3 = (TImage*)img->Clone("img3");
61  img3->Merge(img2, "allanon");
62  img3->Draw();
63 
64  // contrasting (tint with itself)
65  c1->cd(3);
66  TImage *img4 = (TImage*)img->Clone("img4");
67  img4->Merge(img4, "tint");
68 
69  // draw filled rectangle with magenta color
70  img4->FillRectangle("#FF00FF", 20, 220, 40, 40);
71 
72  // Render multipoint alpha-blended gradient (R->G->B)
73  img4->Gradient(0, "#FF0000 #00FF00 #220000FF", 0, 50, 50, 100, 100);
74 
75  // draw semi-transparent 3D button
76  img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, 0);
77  img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
78  img4->Draw();
79 
80  // vectorize image. Reduce palette to 256 colors
81  c1->cd(4);
82  TImage *img5 = (TImage*)img->Clone("img5");
83  img5->Vectorize(256);
84  img5->Draw();
85 
86  // quantization of the image
87  c1->cd(5);
88  TImage *img6 = (TImage*)img->Clone("img6");
89  TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
90  TArrayD *arr = img6->GetArray(50, 40, pal);
91  img6->SetImage(arr->GetArray(), 50, 40, pal);
92  img6->Draw();
93 
94  // HSV adjustment (convert red to yellow)
95  c1->cd(6);
96  TImage *img7 = (TImage*)img->Clone("img7");
97  img7->HSV(0, 40, 40);
98  img7->Draw();
99 }