OnLoadInfo... example for C++ Builder
Take the following steps to exercise the OnLoadInfo event and LoadInfo... properties. The example creates a raw FAX file, then loads the file it just created. (Getting format information from an unfamiliar file is beyond the scope of this example.)
1. |
Start with the project that you created in Loading and Displaying an Image. |
2. |
Add the following declarations to the private section of the Unit1 header file. In online help, you can copy the block of code and paste it into your application. |
//Declare variables for demonstrating raw FAX.
int MyInfoBits;
int MyInfoFlags;
int MyInfoFormat;
int MyInfoHeight;
long MyInfoOffset;
int MyInfoWidth;
int MyInfoXRes;
int MyInfoYRes;
3. |
Add a CommandButton control and code its click procedure as follows: |
void __fastcall TForm1::Button1Click(TObject *Sender)
{
/*Make the image look OK as a 1-bit image.*/
Lead1->Size(Lead1->Width, Lead1->Height, SIZE_RESAMPLE);
Lead1->Halftone(HT_VIEW, 45);
/*Set the form-level variables to the values we will use when loading.*/
MyInfoBits = 1;
MyInfoFlags = LOADINFO_TOPLEFT;
MyInfoFormat = FILE_FAX_G3_2D;
MyInfoHeight = Lead1->BitmapHeight;
MyInfoOffset = 0;
MyInfoWidth = Lead1->BitmapWidth;
MyInfoXRes = Lead1->BitmapXRes;
MyInfoYRes = Lead1->BitmapYRes;
/*Save the image as raw FAX;) load the saved file.*/
/*Format information will be supplied in the OnLoadInfo event.*/
Lead1->Save("C:\\lead\\IMAGES\\TMP.Tif(", FILE_FAX_G3_2D, 1, 1, SAVE_OVERWRITE);
Lead1->Load("C:\\lead\\IMAGES\\TMP.Tif(", 0, 0, 1);
/*Repaint the newly loaded image.*/
Lead1->ForceRepaint();
}
4. |
Code the Lead1 control's OnLoadInfo event as follows: |
void __fastcall TForm1::Lead1LoadInfo(TObject *Sender)
{
/*Use the form-level variables to supply format information.*/
Lead1->LoadInfoBits = MyInfoBits;
Lead1->LoadInfoFlags = MyInfoFlags;
Lead1->LoadInfoFormat = MyInfoFormat;
Lead1->LoadInfoHeight = MyInfoHeight;
Lead1->LoadInfoOffset = MyInfoOffset;
Lead1->LoadInfoWidth = MyInfoWidth;
Lead1->LoadInfoXRes = MyInfoXRes;
Lead1->LoadInfoYRes = MyInfoYRes;
}
5. |
Run your program to test it. |