Logo ROOT  
Reference Guide
rose_image.C File Reference

Detailed Description

View in nbviewer Open in SWAN Display image in a new canvas and pad.

#include "TImage.h"
#include "TCanvas.h"
#include "TArrayD.h"
#include "TROOT.h"
#include "TColor.h"
#include "TAttImage.h"
#include "TEnv.h"
void rose_image()
{
TImage *img = TImage::Open(dir + "/image/rose512.jpg");
if (!img) {
printf("Could not create an image... exit\n");
return;
}
img->SetConstRatio(0);
TString bc = "BlackChancery.ttf";
TString ar = "arial.ttf";
// draw text over image with funny font
img->DrawText(120, 160, "Hello World!", 32,
gROOT->GetColor(4)->AsHexString(),
// draw text over image with foreground specified by pixmap
img->DrawText(250, 350, "goodbye cruel world ...", 24, 0,
ar, TImage::kPlain, dir + "/image/fore.xpm");
TImage *img2 = TImage::Open(dir + "/image/mditestbg.xpm");
// tile image
img2->Tile(img->GetWidth(), img->GetHeight());
c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
c1->Divide(2, 3);
c1->cd(1);
img->Draw("xxx");
c1->cd(2);
// averaging with mditestbg.xpm image
TImage *img3 = (TImage*)img->Clone("img3");
img3->Merge(img2, "allanon");
img3->Draw();
// contrasting (tint with itself)
c1->cd(3);
TImage *img4 = (TImage*)img->Clone("img4");
img4->Merge(img4, "tint");
// draw filled rectangle with magenta color
img4->FillRectangle("#FF00FF", 20, 220, 40, 40);
// Render multipoint alpha-blended gradient (R->G->B)
img4->Gradient(0, "#FF0000 #00FF00 #220000FF", 0, 50, 50, 100, 100);
// draw semi-transparent 3D button
img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, 0);
img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
img4->Draw();
// vectorize image. Reduce palette to 256 colors
c1->cd(4);
TImage *img5 = (TImage*)img->Clone("img5");
img5->Vectorize(256);
img5->Draw();
// quantization of the image
c1->cd(5);
TImage *img6 = (TImage*)img->Clone("img6");
TArrayD *arr = img6->GetArray(50, 40, pal);
img6->SetImage(arr->GetArray(), 50, 40, pal);
img6->Draw();
// HSV adjustment (convert red to yellow)
c1->cd(6);
TImage *img7 = (TImage*)img->Clone("img7");
img7->HSV(0, 40, 40);
img7->Draw();
}
Author
Valeriy Onuchin

Definition in file rose_image.C.

TImage::Gradient
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:168
TImage::Clone
virtual TObject * Clone(const char *) const
Make a clone of an object using the Streamer facility.
Definition: TImage.h:111
TAttImage::kImgBest
@ kImgBest
Definition: TAttImage.h:68
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TImage::SetEditable
virtual void SetEditable(Bool_t=kTRUE)
Definition: TImage.h:225
TAttImage.h
TImage::Merge
virtual void Merge(const TImage *, const char *="alphablend", Int_t=0, Int_t=0)
Definition: TImage.h:172
TAttImage::SetConstRatio
virtual void SetConstRatio(Bool_t constRatio=kTRUE)
Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
Definition: TAttImage.cxx:641
TImage::kPlain
@ kPlain
Definition: TImage.h:59
TImage::DrawText
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:200
TROOT::GetTutorialDir
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition: TROOT.cxx:3021
TImage
Definition: TImage.h:29
TColor.h
TImage::GetHeight
virtual UInt_t GetHeight() const
Definition: TImage.h:229
TCanvas.h
TEnv.h
TImage::Open
static TImage * Open(const char *file, EImageFileTypes type=kUnknown)
Open a specified image file.
Definition: TImage.cxx:118
TString
Definition: TString.h:136
TImage::DrawLine
virtual void DrawLine(UInt_t, UInt_t, UInt_t, UInt_t, const char *="#000000", UInt_t=1)
Definition: TImage.h:184
TImage.h
TROOT.h
TImage::Tile
virtual void Tile(UInt_t, UInt_t)
Definition: TImage.h:148
TArrayD.h
TArrayD::GetArray
const Double_t * GetArray() const
Definition: TArrayD.h:49
TAttImage::SetImageQuality
virtual void SetImageQuality(EImageQuality lquality)
Definition: TAttImage.h:99
TImage::FillRectangle
virtual void FillRectangle(const char *=0, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:192
TImage::GetArray
virtual TArrayD * GetArray(UInt_t=0, UInt_t=0, TImagePalette *=gWebImagePalette)
Definition: TImage.h:234
TImage::Vectorize
virtual Double_t * Vectorize(UInt_t=256, UInt_t=4, Int_t=0)
Definition: TImage.h:161
TImage::GetWidth
virtual UInt_t GetWidth() const
Definition: TImage.h:228
TImage::HSV
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::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
TCanvas
Definition: TCanvas.h:23
TAttImage::GetPalette
virtual const TImagePalette & GetPalette() const
Definition: TAttImage.h:88
TImagePalette
Definition: TAttImage.h:33
TImage::SetImage
virtual void SetImage(const Double_t *, UInt_t, UInt_t, TImagePalette *=0)
Definition: TImage.h:116
TArrayD
Definition: TArrayD.h:27
TImage::Bevel
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
gROOT
#define gROOT
Definition: TROOT.h:406
TImage::kShadeBelow
@ kShadeBelow
Definition: TImage.h:63
c1
return c1
Definition: legend1.C:41