Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
19TCanvas *c1;
20
21void rose_image()
22{
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(false);
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, gROOT->GetColor(4)->AsHexString(), bc, TImage::kShadeBelow);
40
41 // draw text over image with foreground specified by pixmap
42 img->DrawText(250, 350, "goodbye cruel world ...", 24, nullptr, ar, TImage::kPlain, dir + "/image/fore.xpm");
43
44 TImage *img2 = TImage::Open(dir + "/image/mditestbg.xpm");
45
46 // tile image
47 img2->Tile(img->GetWidth(), img->GetHeight());
48
49 c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
50 c1->Divide(2, 3);
51 c1->cd(1);
52 img->Draw("xxx");
53 img->SetEditable(kTRUE);
54
55 c1->cd(2);
56 // averaging with mditestbg.xpm image
57 TImage *img3 = (TImage *)img->Clone("img3");
58 img3->Merge(img2, "allanon");
59 img3->Draw();
60
61 // contrasting (tint with itself)
62 c1->cd(3);
63 TImage *img4 = (TImage *)img->Clone("img4");
64 img4->Merge(img4, "tint");
65
66 // draw filled rectangle with magenta color
67 img4->FillRectangle("#FF00FF", 20, 220, 40, 40);
68
69 // Render multipoint alpha-blended gradient (R->G->B)
70 img4->Gradient(0, "#FF0000 #00FF00 #220000FF", nullptr, 50, 50, 100, 100);
71
72 // draw semi-transparent 3D button
73 img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, false);
74 img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
75 img4->Draw();
76
77 // vectorize image. Reduce palette to 256 colors
78 c1->cd(4);
79 TImage *img5 = (TImage *)img->Clone("img5");
80 img5->Vectorize(256);
81 img5->Draw();
82
83 // quantization of the image
84 c1->cd(5);
85 TImage *img6 = (TImage *)img->Clone("img6");
86 TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
87 TArrayD *arr = img6->GetArray(50, 40, pal);
88 img6->SetImage(arr->GetArray(), 50, 40, pal);
89 img6->Draw();
90
91 // HSV adjustment (convert red to yellow)
92 c1->cd(6);
93 TImage *img7 = (TImage *)img->Clone("img7");
94 img7->HSV(0, 40, 40);
95 img7->Draw();
96}
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define gROOT
Definition TROOT.h:406
Array of doubles (64 bits per element).
Definition TArrayD.h:27
const Double_t * GetArray() const
Definition TArrayD.h:43
virtual const TImagePalette & GetPalette() const
Definition TAttImage.h:88
virtual void SetImageQuality(EImageQuality lquality)
Definition TAttImage.h:99
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
The Canvas class.
Definition TCanvas.h:23
A class to define a conversion from pixel values to pixel color.
Definition TAttImage.h:33
An abstract interface to image processing library.
Definition TImage.h:29
virtual void SetEditable(Bool_t=kTRUE)
Definition TImage.h:225
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition TImage.cxx:118
virtual UInt_t GetWidth() const
Definition TImage.h:228
virtual Double_t * Vectorize(UInt_t=256, UInt_t=4, Int_t=0)
Definition TImage.h:161
virtual void DrawText(Int_t=0, Int_t=0, const char *="", Int_t=12, const char *=nullptr, const char *="fixed", EText3DType=TImage::kPlain, const char *=nullptr, Float_t=0)
Definition TImage.h:200
virtual void FillRectangle(const char *=nullptr, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition TImage.h:192
virtual void Tile(UInt_t, UInt_t)
Definition TImage.h:148
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition TImage.h:184
virtual void Gradient(UInt_t=0, const char *="#FFFFFF #000000", const char *=nullptr, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition TImage.h:168
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:178
virtual TArrayD * GetArray(UInt_t=0, UInt_t=0, TImagePalette *=gWebImagePalette)
Definition TImage.h:234
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition TImage.h:172
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=nullptr)
Definition TImage.h:116
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:164
TObject * Clone(const char *) const override
Make a clone of an object using the Streamer facility.
Definition TImage.h:111
@ kPlain
Definition TImage.h:59
@ kShadeBelow
Definition TImage.h:63
virtual UInt_t GetHeight() const
Definition TImage.h:229
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition TROOT.cxx:3119
Basic string class.
Definition TString.h:139
return c1
Definition legend1.C:41