#include "TImage.h" #include "TCanvas.h" #include "TArrayD.h" #include "TROOT.h" #include "TColor.h" #include "TAttImage.h" TCanvas *c1; void rose_image_mod() { // Display image in a new canvas and pad. Double_t x[5] = {.3,.5,.5,.3,0.3}; Double_t y[5] = {.6,.6,.8,.8,0.6}; TPolyLine *pline = new TPolyLine(5,x,y); pline->SetFillStyle(4000); pline->SetLineColor(2); pline->SetLineWidth(2); pline->SetUniqueID(5); TImage *img = TImage::Open("rose512.jpg"); if (!img) { printf("Could not create an image... exit\n"); return; } c1 = new TCanvas("rose512", "examples of image manipulations", 700, 700); img->Draw(); //pline->Draw("f"); pline->Draw(); //img->SetEditable(kFALSE); c1->AddExec("ex","ROIClicked()"); } void ROIClicked() { //this action function is called whenever you move the mouse //it just prints the id of the picked ROI //you can add graphics actions instead int event = gPad->GetEvent(); if (event != 11) return; //may be comment this line TObject *select = gPad->GetSelected(); if (!select) return; if (select->InheritsFrom("TPolyLine")) { TPolyLine *pl = (TPolyLine*)select; printf("You have clicked ROI %d, color=%d\n", pl->GetUniqueID(),pl->GetFillColor()); } }