rose_image.C

Go to the documentation of this file.
00001 #include "TImage.h"
00002 #include "TCanvas.h"
00003 #include "TArrayD.h"
00004 #include "TROOT.h"
00005 #include "TColor.h"
00006 #include "TAttImage.h"
00007 #include "TEnv.h"
00008 
00009 TCanvas *c1;
00010 
00011 void rose_image()
00012 {
00013    // Display image in a new canvas and pad.
00014    //Author: Valeriy Onuchin
00015    
00016    TImage *img = TImage::Open("rose512.jpg");
00017 
00018    if (!img) {
00019       printf("Could not create an image... exit\n");
00020       return;
00021    }
00022 
00023    img->SetConstRatio(0);
00024    img->SetImageQuality(TAttImage::kImgBest);
00025 
00026    TString fp = gEnv->GetValue("Root.TTFontPath", "");
00027    TString bc = fp + "/BlackChancery.ttf";
00028    TString ar = fp + "/arial.ttf";
00029 
00030    // draw text over image with funny font
00031    img->DrawText(120, 160, "Hello World!", 32, 
00032                  gROOT->GetColor(4)->AsHexString(), 
00033                  bc, TImage::kShadeBelow);
00034 
00035    // draw text over image with foreground specified by pixmap
00036    img->DrawText(250, 350, "goodbye cruel world ...", 24, 0, 
00037                  ar, TImage::kPlain, "fore.xpm");
00038 
00039    TImage *img2 = TImage::Open("mditestbg.xpm");
00040 
00041    // tile image
00042    img2->Tile(img->GetWidth(), img->GetHeight());
00043 
00044    c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
00045    c1->Divide(2, 3);
00046    c1->cd(1);
00047    img->Draw("xxx");
00048    img->SetEditable(kTRUE);
00049 
00050    c1->cd(2);
00051    // averaging with mditestbg.xpm image
00052    TImage *img3 = (TImage*)img->Clone("img3");
00053    img3->Merge(img2, "allanon");
00054    img3->Draw();
00055 
00056    // contrasting (tint with itself)
00057    c1->cd(3);
00058    TImage *img4 = (TImage*)img->Clone("img4");
00059    img4->Merge(img4, "tint");
00060 
00061    // draw filled rectangle with magenta color
00062    img4->FillRectangle("#FF00FF", 20, 220, 40, 40);
00063 
00064    // Render multipoint alpha-blended gradient (R->G->B)
00065    img4->Gradient(0, "#FF0000 #00FF00 #220000FF", 0, 50, 50, 100, 100);
00066 
00067    // draw semi-transparent 3D button
00068    img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, 0);
00069    img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
00070    img4->Draw();
00071 
00072    // vectorize image. Reduce palette to 256 colors
00073    c1->cd(4);
00074    TImage *img5 = (TImage*)img->Clone("img5");
00075    img5->Vectorize(256);
00076    img5->Draw();
00077 
00078    // quantization of the image
00079    c1->cd(5);
00080    TImage *img6 = (TImage*)img->Clone("img6");
00081    TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
00082    TArrayD *arr = img6->GetArray(50, 40, pal);
00083    img6->SetImage(arr->GetArray(), 50, 40, pal);
00084    img6->Draw();
00085 
00086    // HSV adjustment (convert red to yellow)
00087    c1->cd(6);
00088    TImage *img7 = (TImage*)img->Clone("img7");
00089    img7->HSV(0, 40, 40);
00090    img7->Draw();
00091 }

Generated on Tue Jul 5 15:44:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1