Board index » cppbuilder » TImage: Loading JPG and Gif from Stream

TImage: Loading JPG and Gif from Stream

I have a TPicture object and want to load different pictures from stream
into this component. if i load only gifs or only jpgs there is no
problem but if i mix it i get an exception. if i'am doing  the same with
loading the pictures from file i'am having no problems.
My solution for this was now to store the pictype in the database and
before i load the picture from the stream into tpicure component i load
a little gif or jpg file into the timage object. And everything works
fine. But this should only be a workaround. Is there any possibility to
tell the TImage object that the stream data is now a gif or a jpg.
thanks for reading this

A.Wehner

int __fastcall LoadFromDBToPic (TTable *Table, TPicture *Bild)
{
int PicType;
TJPEGImage *jpegimage = dynamic_cast<TJPEGImage *>(Bild->Graphic);
TGIFImage  *gifimage  = dynamic_cast<TGIFImage  *>(Bild->Graphic);

   if (Table->FieldByName("Bild")->IsNull)
      return GENERAL_ERR;

  // Workarounf
   PicType = Table->FieldByName("PicType")->AsInteger;
   if (PicType == GIF)
   {
        Bild->LoadFromFile(ExtractFilePath(ParamStr(0))+"gifbild.gif");
        DBModule->LoadBlobFromStream(Bild->Graphic,Table,"Bild");
   }
   else
   {
        Bild->LoadFromFile(ExtractFilePath(ParamStr(0))+"jpgbild.jpg");
        DBModule->LoadBlobFromStream(Bild->Graphic,Table,"Bild");
   }
   return NO_ERR;

Quote
}

 

Re:TImage: Loading JPG and Gif from Stream


Hi Andreas,

Quote
Andreas Wehner wrote:
> Is there any possibility to
> tell the TImage object that the stream data is now a gif or a jpg.

You mean TPicture, right?

What was the original code?

AFAIK, this should work:

TPicture* APicture = new TPicture();

APicture->LoadFromFile("myjpg.jpg");
APicture->LoadFromFile("mygif.gif");

HTH,

Micha.

Re:TImage: Loading JPG and Gif from Stream


Quote
Andreas Wehner <Weh...@ass-gmbh.com> wrote:
>But this should only be a workaround. Is there any possibility to
>tell the TImage object that the stream data is now a gif or a jpg.

It's been awhile since I wrote any C++, but try the following.

Assign your TGraphic descendant to TPicture like this...

TGIFImage *gifimage = new TGIFImage();
Bild->Assign(gifimage);
delete gifimage;

...and then let the TGraphic load itself from the stream:

Bild->Graphic->LoadFromStream(...);

DIXI

+--------------------from usenet----------------------+
|  Anders Bo Melander    | mailto:and...@melander.dk  |
|  Denmark               | http://www.melander.dk     |
+------------------------+----------------------------+

Other Threads