Problems with SetImage(double ...)

Hi All
I have some problems.
I wrote this code, but if I try to call more time this function “DoDraw”, my program exits or shows this message:

 /*  *** Break *** segmentation violation
      Generating stack trace...             */

Second thing, I don’t knows how to manage color,
the function Setimage want a *double,and I don’t know How to convert a rgb color inwhich red green and blue are represented by numbers between 0-255 in a double number

[code]
MianFrame::DoDraw()
{
TImage *img1;
img1 = TImage::Open(“1.pgm”);
double *vt= new double(4);
for (int i=0;i<4;i++)
vt[i]=1;

img1->SetImage(vt, 2,2,0);
img1->SetConstRatio(0);
img1->SetImageQuality(TAttImage::kImgBest);

img1->Draw();
fCanvas->Update();
delete img1;
delete []vt;
][/code]

Tnak you very much
Patof

Hi,

what you want to do is not possible yet. You can only display TImage’s in a TCanvas or a TRootEmbeddedCanvas, not directly in a TGMainFrame.

Further, the double arrays are only used if you want to set image data coming from another source (e.g. 2d array, CCD, etc.), not from a picture like l.pgm.

Have a look at the $ROOTSYS/tutorials/galaxy_image.C and rose_image.C

Cheers, Fons.

Hi Patof,

You have a syntax error (or maybe a typo) which could lead to any sort of problem.

You wrote:

double *vt= new double(4); for (int i=0;i<4;i++) vt[i]=1;
This actually does
[ul]allocates enough memory for only ONE double and assigns it the value 4
write out-of bounds for 3 doubles causing all sort of possible problems.[/ul]
The correct code would be:

double *vt= new double[4]; for (int i=0;i<4;i++) vt[i]=1;
Note the brackets instead of paranthesis.

Cheers,
Philippe.

thanks all
Now I try your tips