本文整理汇总了C++中TImage::Merge方法的典型用法代码示例。如果您正苦于以下问题:C++ TImage::Merge方法的具体用法?C++ TImage::Merge怎么用?C++ TImage::Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TImage
的用法示例。
在下文中一共展示了TImage::Merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trans_graph
void trans_graph()
{
// remember if we are in batch mode
Bool_t batch = gROOT->IsBatch();
// switch to batch mode
gROOT->SetBatch(kTRUE);
// execute graph.C macro
gROOT->Macro("$ROOTSYS/tutorials/graphs/graph.C");
// create gVirtualPS object
TImageDump dmp("dummy.png");
TImage *fore = dmp.GetImage(); // image associated with image_dump
// resize canvas
gPad->SetCanvasSize(400, 300);
gPad->Paint(); // paint gPad on fore image associated with TImageDump
// open background image
TImage *back = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
// choose colors to be transparent
TColor *bk1 = gROOT->GetColor(gPad->GetFillColor());
TColor *bk2 = gROOT->GetColor(gPad->GetFrame()->GetFillColor());
UInt_t rgb1 = color2rgb(bk1);
UInt_t rgb2 = color2rgb(bk2);
// get directly accessible ARGB array
UInt_t *argb = fore->GetArgbArray();
UInt_t w = fore->GetWidth();
UInt_t h = fore->GetHeight();
// scan all pixels in fore image and
// make rgb1, rgb2 colors transparent.
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
}
}
}
// alphablend back and fore images
back->Merge(fore, "alphablend", 20, 20);
// write result image in PNG format
back->WriteImage("trans_graph.png");
printf("*************** File trans_graph.png created ***************\n");
delete back;
// switch back to GUI mode
if (!batch) gROOT->SetBatch(kFALSE);
}