Loading and Displaying an Image (C++ Builder 4.0)
Take the following steps to start a project and to add some code that displays an image on the main form:
1. |
Start C++ Builder 4.0. |
|
2. |
If you didn’t install LEAD RasterView Control, install it. |
|
|
On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD RasterView Control (14.5), and Press install. |
|
3. |
Select the LEAD RasterView control; then add the control to your main form. Size and position the control, as you want it to appear at run time. |
|
4. |
Add a button to your form and name it as follows: |
|
|
Name |
Caption |
|
LoadLead |
Load Image |
5. |
Code the main form's Create procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//Set defaults for displaying the image
//These are all persistent properties that can be set in the properties
box->
LEADRasterView1->Appearance
= RASTERVIEW_APPEARANCE_FLAT;
LEADRasterView1->BorderStyle
= 1;
LEADRasterView1->BackColor
= (TColor)RGB(255, 255, 125);
LEADRasterView1->PaintDither
= PAINTDITHER_DIFFUSION;
LEADRasterView1->PaintPalette
= PAINTPALETTE_AUTO;
LEADRasterView1->AutoRepaint
= True;
LEADRasterView1->AutoSize
= False;
LEADRasterView1->AutoSetRects
= True;
LEADRasterView1->PaintSizeMode
= PAINTSIZEMODE_FIT;
LEADRasterView1->EnableFireMouse2Event
= true;
}
6. |
Code the LoadLead button's click procedure as follows: |
void __fastcall TForm1::LoadLeadClick(TObject *Sender)
{
ILEADRasterIO * pRasterIO;
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO,
(void**)&pRasterIO);
pRasterIO->Load (LEADRasterView1->Raster, AnsiToOLESTR("v:\\images\\image1.cmp"),
0, 0, 1);
pRasterIO->Release();
}
7. |
On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO object library (14.5), and Press Ok. |
8. |
At the beginning of the Unit1.h file, Include these files. |
#include "Ltrasteriolib_tlb.h"
#include "Ltrasterlib_tlb.h"
9. |
Run your program to test it. |
10. |
Save the project to use as a starting point for other tasks in this tutorial. |