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 

Stream a imagen

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





PostPosted: Wed May 25, 2005 4:12 am    Post subject: Stream a imagen Reply with quote




Hi:

I'm writing a picture (Image1) to a stream and writing this
stream to other images (Image2), but I get an Access violation address...

The code is below

TMemoryStream* pms = new TMemoryStream;
Image1->Picture->Graphic->SaveToStream(pms);
pms->Seek(0, soFromBeginning);
Image2->Picture->Graphic->LoadFromStream(pms);

What is wrong?

Thanks
Back to top
Hans Galema
Guest





PostPosted: Wed May 25, 2005 6:47 am    Post subject: Re: Stream a imagen Reply with quote



Ernesto Rod wrote:

Quote:
TMemoryStream* pms = new TMemoryStream;
Image1->Picture->Graphic->SaveToStream(pms);
pms->Seek(0, soFromBeginning);
Image2->Picture->Graphic->LoadFromStream(pms);

What is wrong?

You forgot to tell on which line you got the AV.

Graphic is not yet initialised for Image2. Try:

TMemoryStream* pms = new TMemoryStream;
Image1->Picture->Bitmap->SaveToStream(pms);
pms->Seek(0, soFromBeginning);
Image2->Picture->Bitmap->LoadFromStream(pms);
delete pms;

Hans.

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed May 25, 2005 7:14 am    Post subject: Re: Stream a imagen Reply with quote




"Hans Galema" <notused (AT) notused (DOT) nl> wrote


Quote:
Image1->Picture->Bitmap->SaveToStream(pms);
pms->Seek(0, soFromBeginning);
Image2->Picture->Bitmap->LoadFromStream(pms);

That will only work if there is a Bitmap loaded in Image1 to begin with. If
there is any other image format loaded, then accessing the Bitmap property
will wipe out that image completely and you will end up streaming empty
data.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed May 25, 2005 7:15 am    Post subject: Re: Stream a imagen Reply with quote


"Ernesto Rod" <enriquevald (AT) yahoo (DOT) com> wrote


Quote:
Image1->Picture->Graphic->SaveToStream(pms);

Is there an actual Graphic loaded in the TImage before saving the stream?
If not, then the Graphic property will be NULL.

Quote:
Image2->Picture->Graphic->LoadFromStream(pms);

Is there an actual Graphic loaded in the TImage before loading the stream?
If not, then the Graphic property will be NULL.

Even if both Graphic properties are not NULL, you must ensure that they are
the same class type, otherwise LoadFromStream() will fail. For example, if
Image1 has a TJPEGImage loaded, then you must first assign a TJPEGImage to
Image2 before calling LoadFromStream().

There is an easier way to pass an image from one TPicture to another - just
assign them directly, ie:

Image2->Picture->Assign(Image1->Picture);


Gambit




Back to top
Hans Galema
Guest





PostPosted: Wed May 25, 2005 7:59 am    Post subject: Re: Stream a imagen Reply with quote

Remy Lebeau (TeamB) wrote:

Quote:
Image1->Picture->Bitmap->SaveToStream(pms);
pms->Seek(0, soFromBeginning);
Image2->Picture->Bitmap->LoadFromStream(pms);


That will only work if there is a Bitmap loaded in Image1 to begin with.

Yes. If not specified I assume a Bitmap.

Hans.

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.