| View previous topic :: View next topic |
| Author |
Message |
Ernesto Rod Guest
|
Posted: Wed May 25, 2005 4:12 am Post subject: Stream a imagen |
|
|
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
|
Posted: Wed May 25, 2005 6:47 am Post subject: Re: Stream a imagen |
|
|
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
|
Posted: Wed May 25, 2005 7:14 am Post subject: Re: Stream a imagen |
|
|
"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
|
Posted: Wed May 25, 2005 7:15 am Post subject: Re: Stream a imagen |
|
|
"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
|
Posted: Wed May 25, 2005 7:59 am Post subject: Re: Stream a imagen |
|
|
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 |
|
 |
|