Position images on canvas

Hello,

I’d like to make up a 2D repeating pattern (for teaching crystallography) by positioning an image many times (in rows and columns) on a canvas. I can position text characters using TText without problems.

I looked at TAsimage::Tile, but I don’t see how to make it do what I want.

I’m using Version 5.27/02 on Linux.

If anyone knows how to accomplish this task, I’d appreciate some help.

Thanks,
Roger

Have look at $ROOTSYS/tutorials/image/rose_image.C

Thank you for the reply Oliver.

However, what I want to do is slightly different: I want the image to be repeated in a single pad, and to be able to have it arranged in rows & columns that could be non-orthogonal.

Thanks,
Roger

You need to use several pad. The pad is filled by the image.
Do the tiling with the pads and draw the images inside.
Here is an example (in your case you should define the pads one by one at the right positions):

void simple_rose_image()
{
   TCanvas *c1;
   TImage *img = TImage::Open("rose512.jpg");
   img->SetConstRatio(0);
   img->SetImageQuality(TAttImage::kImgBest);

   c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
   c1->Divide(2, 3, 0 , 0);
   for (int i=1; i<=6;i++) {
     c1->cd(i);
     img->Draw("xxx");
   }
}

Thank you again Oliver.

That does some of what I want.
It looks as though I will need to find some other tool in order to get non-orthogonal tilings.

Regards,
Roger

Not necessarily, because you can create pads at the position you want. They will be rectangular though, but pictures are rectangular anyway. In this example I used the Divide() method to quickly create pads, but in your case you should create the pads at the exact position you need (as I suggested in my previous post).

Thank you again Oliver. Now I understand. Sorry to be so slow!

Cheers,
Roger

This puts the two sub-pads in the specified positions, but the image is drawn on the parent canvas:

[code]void arbitrary_pad()
{
TCanvas *c1;
TImage *img = TImage::Open(“rose512.jpg”);
img->SetConstRatio(0);
img->SetImageQuality(TAttImage::kImgBest);

Double_t bordersize = 0;
Double_t bordermode = 0;

c1 = new TCanvas(“c1”, “Arbitrary Canvas Subdivisions”, 760, 900);

p1 = new TPad(“c1_1”,“p1”,0.2,0.2,0.5,0.5,bordersize,bordermode);
p1->Draw();
c1->cd(1);
img->Draw(“xxx”);

p2 = new TPad(“c1_2”,“p2”,0.7,0.7,0.9,0.9,bordersize,bordermode);
p2->Draw();
c1->cd(2);
img->Draw(“xxx”);

}[/code]
What am I doing wrong?

Thanks,
Roger

do p1->cd(), p2->cd()…
instead of c1->cd(1) etc …