Writing and Reading Multi-Page Files (C++ Builder 6.0)

Take the following steps to create a multi-page file, then load and display the images from the file. Only TIFF (MPT) and PCX (DCX) formats support Multi-Page files.

1.

Start C++ Builder.

2.

If you didn’t install the LEAD Raster View Control, install it as follows:

 

On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD Raster View Control (14.5). Press Install.

3

Add 2 LEAD Raster View controls to your main form. The size and position does not matter.

4.

On the Project pull-down menu, use the Import Type library… and install the LEAD Raster IO object library (14.5). Press OK.

5.

Add 2 LEAD Raster IO controls from the ActiveX tab to your form.

6.

Add a button to your form and name it as follows:

 

Name

Caption

 

btnLoad

Load Multi-Page File

7.

Code the btnLoad Click’s procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. This code loads two bitmaps, saves them both into a single multi-page TIFF file, loads them again from the TIFF file, and displays them side-by-side.

void __fastcall TForm1::btnLoadClick(TObject *Sender) 
{
     int HeightFactor1, WidthFactor1; 
     int HeightFactor2, WidthFactor2; 
     int HeightAllowed, WidthAllowed; 
     int ImageWidth1, ImageHeight1; 
     int ImageWidth2, ImageHeight2; 

     //Disable automatic repainting of the image. 
     LEADRasterView1->AutoRepaint = False; 
     LEADRasterView2->AutoRepaint = False; 
     //Turn off scroll bars to make sure we use the full client area
     LEADRasterView1->AutoScroll = False; 
     LEADRasterView2->AutoScroll = False; 
     //Position and size the main form so that it takes up most of the screen
     Width = Screen->Width * 0.9 ; 
     Height= Screen->Height* 0.8 ; 
     Left = (Screen->Width- Width) / 2; 
     Top = (Screen->Height- Height)/ 2; 
     //Display the form and set the mouse pointer to an hourglass

     Screen->Cursor = crHourGlass; 
     //Load the bitmaps-> These hard-coded path names may be different on your system
     LEADRasterIO1->Load ( LEADRasterView1->Raster, AnsiToOLESTR("c:\\image1.cmp"),0, 0, 1 ) ; 
     LEADRasterIO2->Load ( LEADRasterView2->Raster, AnsiToOLESTR("c:\\image2.cmp"),0, 0, 1 ) ; 

     //Save the bitmaps to a single multipage TIFF file
     LEADRasterIO1->Save ( LEADRasterView1->Raster, AnsiToOLESTR("c:\\combined.mpt"), FILE_TIF, 24,(QFactorConstants)0, SAVE_OVERWRITE);
     LEADRasterIO2->Save ( LEADRasterView2->Raster, AnsiToOLESTR("c:\\combined.mpt"), FILE_TIF, 24,(QFactorConstants)0, SAVE_APPEND);
     //Get information about the images so that we can size the controls
     LEADRasterIO1->GetFileInfo ( LEADRasterView1->Raster, WideString("c:\\combined.mpt"), 1, 0 ) ;
     LEADRasterIO2->GetFileInfo ( LEADRasterView2->Raster, WideString("c:\\combined.mpt"), 2, 0 );
     //Clear the bitmaps from memory
     LEADRasterView1->Raster->Bitmap = 0;
     LEADRasterView2->Raster->Bitmap = 0;
     //Make the controls visible so that we can size and position them
     //They will not really appear until we load an image and paint it
     LEADRasterView1->Visible = True;
     LEADRasterView2->Visible = True;
     //Set the variables used for preserving the aspect ratio
     HeightFactor1 = LEADRasterIO1->InfoHeight
     WidthFactor1 = LEADRasterIO1->InfoWidth
     HeightFactor2 = LEADRasterIO2->InfoHeight
     WidthFactor2 = LEADRasterIO2->InfoWidth
     HeightAllowed = Height * 0.8; 
     WidthAllowed = Width * 0.45; 
     //Center each LEAD control on half of the form, preserving the aspect ratio
     //Check to see if using the maximum width will make the image too tall
     //Set the dimensions based on the result
     if ((WidthAllowed * HeightFactor1) / WidthFactor1 < HeightAllowed) 
     {
      LEADRasterView1->Left = (Width / 4) - (WidthAllowed / 2); 
       LEADRasterView1->Width = WidthAllowed; 
       LEADRasterView1->Height = (LEADRasterView1->Width * HeightFactor1) / WidthFactor1; 
       LEADRasterView1->Top = (Height - LEADRasterView1->Height) / 2; 
     }
     else
     {
      LEADRasterView1->Top = (Height - HeightAllowed) / 2; 
       LEADRasterView1->Height = HeightAllowed; 
       LEADRasterView1->Width = (LEADRasterView1->Height * WidthFactor1) / HeightFactor1; 
       LEADRasterView1->Left = (Width / 4) - (LEADRasterView1->Width / 2); 
     }
     if ((WidthAllowed * HeightFactor2) / WidthFactor2 < HeightAllowed) 
     {
      LEADRasterView2->Left = (Width * 3 / 4) - (WidthAllowed / 2); 
       LEADRasterView2->Width = WidthAllowed; 
       LEADRasterView2->Height = (LEADRasterView2->Width * HeightFactor2) / WidthFactor2; 
       LEADRasterView2->Top = (Height - LEADRasterView2->Height) / 2; 
     }
     else
     {
      LEADRasterView2->Top = (Height - HeightAllowed) / 2; 
       LEADRasterView2->Height = HeightAllowed; 
       LEADRasterView2->Width = (LEADRasterView2->Height * WidthFactor2) / HeightFactor2; 
       LEADRasterView2->Left = (Width * 3 / 4) - (LEADRasterView2->Width / 2); 
     }
     //Load the bitmaps from the multipage TIFF file
     LEADRasterIO1->Load ( LEADRasterView1->Raster, AnsiToOLESTR("c:\\combined.mpt"), 24, 1, 1); 
     LEADRasterIO2->Load ( LEADRasterView2->Raster, AnsiToOLESTR("c:\\combined.mpt"), 24, 2, 1); 
     //Set the image display sizes to match the LEAD controls
     ImageWidth1 = LEADRasterView1->ScaleWidth
     ImageHeight1 = LEADRasterView1->ScaleHeight
     LEADRasterView1->SetDstRect ( 0, 0, ImageWidth1, ImageHeight1); 
     LEADRasterView1->SetDstClipRect ( 0, 0, ImageWidth1, ImageHeight1); 
     //Set the image display sizes to match the LEAD controls
     ImageWidth2 = LEADRasterView2->ScaleWidth
     ImageHeight2 = LEADRasterView2->ScaleHeight
     LEADRasterView2->SetDstRect ( 0, 0, ImageWidth2, ImageHeight2); 
     LEADRasterView2->SetDstClipRect (0, 0, ImageWidth2, ImageHeight2); 

     //Display the images
     LEADRasterView1->ForceRepaint () ; 
     LEADRasterView2->ForceRepaint () ; 
     //Set the mouse pointer back to the default
     Screen->Cursor= crDefault;
}

8.

Run your program to test it.