%%cpp -d #include "TColor.h" #include "TImage.h" #include "TImageDump.h" #include "TVirtualPad.h" #include "TROOT.h" #include "TFrame.h" UInt_t color2rgb(TColor *col) { // returns RGB value of color return ((UInt_t(col->GetRed()*255) << 16) + (UInt_t(col->GetGreen()*255) << 8) + UInt_t(col->GetBlue()*255)); } Bool_t batch = gROOT->IsBatch(); gROOT->SetBatch(kTRUE); gROOT->Macro("$ROOTSYS/tutorials/graphs/graph.C"); TImageDump dmp("dummy.png"); TImage *fore = dmp.GetImage(); // image associated with image_dump gPad->SetCanvasSize(400, 300); gPad->Paint(); // paint gPad on fore image associated with TImageDump TImage *back = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg"); TColor *bk1 = gROOT->GetColor(gPad->GetFillColor()); TColor *bk2 = gROOT->GetColor(gPad->GetFrame()->GetFillColor()); UInt_t rgb1 = color2rgb(bk1); UInt_t rgb2 = color2rgb(bk2); UInt_t *argb = fore->GetArgbArray(); UInt_t w = fore->GetWidth(); UInt_t h = fore->GetHeight(); for (UInt_t i = 0; i < h; i++) { for (UInt_t j = 0; j < w; j++) { Int_t idx = i*w + j; // RGB part of ARGB color UInt_t col = argb[idx] & 0xffffff; // 24..31 bits define transparency of the color in the range 0 - 0xff // for example, 0x00000000 - black color with 100% transparency // 0xff000000 - non-transparent black color if ((col == rgb1) || (col == rgb2)) { // argb[idx] = 0; // 100% transparent } else { argb[idx] = 0xff000000 + col; // make other pixels non-transparent } } } back->Merge(fore, "alphablend", 20, 20); back->WriteImage("trans_graph.png"); printf("*************** File trans_graph.png created ***************\n"); delete back; if (!batch) gROOT->SetBatch(kFALSE); gROOT->GetListOfCanvases()->Draw()