BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TImage Problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Marco
Guest





PostPosted: Mon Jun 28, 2004 9:53 am    Post subject: TImage Problem Reply with quote




Hi, this is my code:

//--------------------------------------------------------------
TImage* Image1 = new TImage(NULL);
Image1->Height = dis_prg->Height;
Image1->Width = dis_prg->Width;
Image1->Top = Top+100;//dis_prg->Top;
Image1->Left = Left+200;//dis_prg->Left+100;
Image1->Canvas->CopyRect(Image1->ClientRect, dis_prg->GetCanvas(), dis_prg->ClientRect);

ImageList_List->Add(Image1->Picture->Bitmap, NULL);
dis_prg->Visible = false;
Image1->Visible = true;
//--------------------------------------------------------------

In this way Image1 does not come visualized.
If i put a TImage Object in my form and i use this code:

//--------------------------------------------------------------
Image1->Height = dis_prg->Height;
Image1->Width = dis_prg->Width;
Image1->Top = Top+100;//dis_prg->Top;
Image1->Left = Left+200;//dis_prg->Left+100;
Image1->Canvas->CopyRect(Image1->ClientRect, dis_prg->GetCanvas(), dis_prg->ClientRect);

ImageList_List->Add(Image1->Picture->Bitmap, NULL);
dis_prg->Visible = false;
Image1->Visible = true;
//--------------------------------------------------------------

all work correctly.

Any idea?

Thanks in advanced.
Back to top
Ramy
Guest





PostPosted: Mon Jun 28, 2004 10:07 am    Post subject: Re: TImage Problem Reply with quote




Hi :-)

I think that to show the Image you must give it a 'Parent'...

You should add the line -

Image1->Parent = this; // Better solution

or

Image1->Parent = Form1;

If the image should be shown on Form1;

Ramy


"Marco" <mleaerdini (AT) hotmail (DOT) it> wrote:
Quote:

Hi, this is my code:

//--------------------------------------------------------------
TImage* Image1 = new TImage(NULL);
Image1->Height = dis_prg->Height;
Image1->Width = dis_prg->Width;
Image1->Top = Top+100;//dis_prg->Top;
Image1->Left = Left+200;//dis_prg->Left+100;
Image1->Canvas->CopyRect(Image1->ClientRect, dis_prg->GetCanvas(), dis_prg->ClientRect);

ImageList_List->Add(Image1->Picture->Bitmap, NULL);
dis_prg->Visible = false;
Image1->Visible = true;
[...]



Back to top
Corey Murtagh
Guest





PostPosted: Mon Jun 28, 2004 10:12 am    Post subject: Re: TImage Problem Reply with quote



Marco wrote:

Quote:
Hi, this is my code:

//--------------------------------------------------------------
TImage* Image1 = new TImage(NULL);
Image1->Height = dis_prg->Height;
Image1->Width = dis_prg->Width;
Image1->Top = Top+100;//dis_prg->Top;
Image1->Left = Left+200;//dis_prg->Left+100;
Image1->Canvas->CopyRect(Image1->ClientRect, dis_prg->GetCanvas(), dis_prg->ClientRect);

ImageList_List->Add(Image1->Picture->Bitmap, NULL);
dis_prg->Visible = false;
Image1->Visible = true;
//--------------------------------------------------------------

In this way Image1 does not come visualized.

When you're creating any VCL control at runtime you have to set the
parent control. For example:

Image1->Parent = Form1;

Also you may find that changing the height and/or width of a TImage at
runtime doesn't change the size of the underly graphic. If you load a
100x100 image into a TImage at design time, then resize the TImage at
runtime to 200x200, you probably can't draw on the extra space.

To solve this, prepare your image in a TBitmap and assign it to the TImage:

TImage* Image1 = new TImage(NULL);
Image1->Parent = Form1;
Image1->Height = dis_prg->Height;
Image1->Width = dis_prg->Width;
Image1->Top = Top + 100;
Image1->Left = Left + 200;

Graphics::TBitmap* bmp = new Graphics::TBitmap();
bmp->Width = dis_prg->Width;
bmp->Height = dis_prg->Height;
TRect r = TRect(0, 0, bmp->Width, bmp->Height);
bmp->Canvas->CopyRect(r, dis_prg->GetCanvas(), r);
Image1->Picture->Bitmap->Assign(bmp);
delete bmp;

//...
Image1->Visible = true;

Quote:
If i put a TImage Object in my form and i use this code:

The designer assigns the parent control for you.

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"

Back to top
Marco
Guest





PostPosted: Mon Jun 28, 2004 11:51 am    Post subject: Re: TImage Problem Reply with quote


Thanks Ramy and Thanks Corey.
Now work correct.

I've another litle problem.
When i start my application i don't know how many bitmap files i have to show.
How can i initialize different bitmap-area on the MainForm after to have read how many bitmap i have to show?

Can i use a list of TRect with different coordinates where i
put my bitmap files?

Thanks again.

Marco
Back to top
Steve Aletto
Guest





PostPosted: Mon Jun 28, 2004 1:03 pm    Post subject: Re: TImage Problem Reply with quote

Quote:
When i start my application i don't know how many bitmap files i
have to show.
How can i initialize different bitmap-area on the MainForm after to
have read how many bitmap i have to show?

Can i use a list of TRect with different coordinates where i
put my bitmap files?

I'd use an array of pointers to Image instead.

Untested:

TImage **MyImage;
const int NumImages = 10;
MyImage = new TImage *[NumImages];
for (int i = 0; i < NumImages; i++)
{
MyImage[i] = new TImage(NULL);
MyImage[i]->Parent = this;
}

...do what you want with MyImage[]...

for (int i = 0; i < NumImages; i++)
delete MyImage[i];
delete[] MyImage;

HTH,

Steve.



Back to top
Marco
Guest





PostPosted: Mon Jun 28, 2004 1:28 pm    Post subject: Re: TImage Problem Reply with quote


Thank you very much Steve, your solution is better.

Bye.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.