Available in the LEADTOOLS Imaging toolkit. |
CreateBitmap, Size, and Combine example for C++ 4.0 and later
This example creates a bitmap for Lead2 (same size and BPS as Lead 1) and fills it with green. It resizes the Lead1 bitmap, then uses a loop to do multiple combines with the Lead2 bitmap. It then copies the Lead2 bitmap to Lead1 and redisplays m_Lead1.
BeginWaitCursor();
// Create the Lead2 bitmap. (The control must already be on the form).
int MyWidth = (int) m_Lead1.GetBitmapWidth();
int MyHeight = (int) m_Lead1.GetBitmapHeight();
int MyBPS = m_Lead1.GetBitmapBits();
m_Lead2.CreateBitmap((float) MyWidth, (float) MyHeight, MyBPS);
m_Lead2.Fill(RGB(0, 255, 0)); // fill with green
// Resize the Lead1 bitmap
int ImageWidth = (int) (MyWidth * 0.3);
int ImageHeight = (int) (MyHeight * 0.3);
m_Lead1.Size((float) ImageWidth, (float) ImageHeight, RESIZE_RESAMPLE);
// Initialize the variables used for multiple combines.
int TestWidth = MyWidth; // Used for horizontal positioning
int TestHeight = MyHeight; // Used for vertical positioning
int VFactor = (int) (MyHeight / ImageHeight) + 1; // Number spaces between images
int VSpacing = (int) ((MyHeight % ImageHeight) / VFactor); // Pixels between images
int HFactor = (int) (MyWidth / ImageWidth) + 1; // Number spaces between images
int HSpacing = (int) ((MyWidth % ImageWidth) / HFactor); // Pixels between images
int DstT = VSpacing; // Top coordinate of the destination rectangle
int SrcL = 0; // Left coordinate of the source rectangle
int SrcT = 0; // Top coordinate of the source rectangle
int DstW = ImageWidth; // Width of the destination rectangle
int DstH = ImageHeight; // Height of the destination rectangle
int MyOp = CB_OP_ADD + CB_DST_0; // Operation flags used when combining images
// Do the loop that does the multiple combines
while(TestHeight > ImageHeight) // Vertical loop
{
DstT = MyHeight - TestHeight + VSpacing;
TestHeight = TestHeight - ImageHeight - VSpacing;
while(TestWidth > ImageWidth) // Horizontal loop
{
int DstL = MyWidth - TestWidth + HSpacing;
TestWidth = TestWidth - ImageWidth - HSpacing;
m_Lead2.Combine((float) DstL, (float) DstT, (float) DstW, (float) DstH,
m_Lead1.GetBitmap(), (float) SrcL, (float) SrcT, MyOp);
}
TestWidth = MyWidth;
}
// Copy the Lead2 bitmap to Lead1
m_Lead1.SetBitmap(m_Lead2.GetBitmap());
// Set the image display size to match the LEAD control
m_Lead1.SetDstRect(0.0f, 0.0f, m_Lead1.GetScaleWidth(), m_Lead1.GetScaleHeight());
m_Lead1.SetDstClipRect(0.0f, 0.0f, m_Lead1.GetScaleWidth(), m_Lead1.GetScaleHeight());
m_Lead1.ForceRepaint(); // Repaint the image
EndWaitCursor();