BitmapDataPath Example for C++ Builder

This example shows how to load an image from the Internet. It uses the BitmapDataPath method to start the asynchronous load; then uses the ReadyStateChange event to paint the image when loading is complete.

 

LEADRasterIO  *pRasterIO;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
   LEADEventSink1->Connect (pRasterIO, DIID__LEADRasterIOEvents);
   pRasterIO->BitmapDataPath (LEADRasterView1->Raster, AnsiToOLESTR("http://www.leadtools.com/images/tiger2.cmp"));
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
   if(pRasterIO)
      pRasterIO-> Release( );
}

void __fastcall TForm1::LEADEventSink1Invoke(TObject *Sender, int DispID,
      const TGUID &IID, int LocaleID, WORD Flags, tagDISPPARAMS &Params,
      Pointer varResult, Pointer ExcepInfo, Pointer ArgErr)
{
   switch (DispID)
   {
     case LEADRASTERIOEVENTS_READYSTATECHANGE:
      {
         int ReadyState = (OleVariant) (Params.rgvarg[0]);
       //Paint the image when loading is complete.
       if (ReadyState == RASTER_READYSTATE_COMPLETE)
       {
              LEADRasterView1->AutoSetRects = True;
              LEADRasterView1->PaintSizeMode = PAINTSIZEMODE_FIT;
              LEADRasterView1->ForceRepaint();
       }
      }
      break;
   }
}