RenderCenter example for C++ Builder
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Declare the variables for print-area measurements.
int SkipSpace;
float UsableWidth, UsableHeight, MaxImageHeight;
//Declare the variables for sizing and positioning the image.
int PrintHeight, PrintWidth;
//Declare variables used for preserving aspect ratios.
float WidthFactor, HeightFactor;
//Set the variables used for preserving the aspect ratio
HeightFactor = LEADImage1->BitmapHeight;
WidthFactor = LEADImage1->BitmapWidth;
//Set the pointer to an hourglass
Screen->Cursor = crHourGlass;
//Establish some print-area dimensions. These are arbitrary values.
SkipSpace = Printer()->PageHeight / 30;
UsableWidth = Printer()->PageWidth - (SkipSpace * 4);
UsableHeight = Printer()->PageHeight - (SkipSpace * 4);
//Get the maximum height of one image,
//assuming two equal-size images and space between them.
MaxImageHeight = (UsableHeight - (2 * SkipSpace)) / 2;
//Size and position the first image, preserving the aspect ratio.
//Check to see if using the maximum width makes the image too tall.
//Set the dimensions based on the result.
if(((UsableWidth * HeightFactor) / WidthFactor) < MaxImageHeight)
{
PrintWidth = UsableWidth;
PrintHeight = (PrintWidth * HeightFactor) / WidthFactor;
}
else
{
PrintHeight = MaxImageHeight;
PrintWidth = (PrintHeight * WidthFactor) / HeightFactor;
}
//Start Printing
Printer()->BeginDoc();
// Set the RenderCenter property to False, so we can print
// the image starting from the point (0, 0)
LEADImage1->RenderCenter= false;
// Print the Image
LEADImage1->Render((int)Printer()->Canvas->Handle, 0, 0, PrintWidth, PrintHeight);
// End Printing
Printer()->EndDoc();
//Set the mouse pointer back to the default
Screen->Cursor= crDefault;
}