Using CB to realize the special display of the image

Source: Internet
Author: User
Tags bmp image

In Web pages, software and games, we can often see the image of a variety of stunt display, such as the center spread, venetian blinds, the lower right launch, such a dynamic image display, often give people a pleasing feeling, to our application added some beauty. In C + + Builder, we can easily implement these features. The following is a specific example of the implementation of the center spread and venetian blinds two display techniques, and explain in C + + Builder image processing basic methods.

Create a new project in C + + Builder, then add an image control to the form, set its Picture property to a BMP image, and adjust the image control to the same size as the picture. Add two button controls on the form, set the Button1 Caption property to "center diffuser", and the Button2 caption property to "venetian blinds."

1. For the "center diffusion" of the implementation, we use certain algorithms, through a certain number of cycles, each display part of the image, starting from the center of the image display, until the image of the overall display.

Add the following code to the Button1 onclick event:

void _fastcall Tform1::button1click (tobject *sender)
{
int i,left,top,width,height;
left = image1->left;
top = image1->top;
width = image1->width;
Height = image1->height;
for (i = 0; I <= width; i++) {
Select part of the image through the coordinates of the image
Image1->left = left + (width-i)/2;
Image1->top = top + HEIGHT/2-i*height/width/2;
Image1->width = i;
Image1->height = I*height/width;
Image1->refresh ();
}
}

2. For "Venetian blinds", we can make use of the rectangular copy (Copyrect) method provided by the canvas (Canvas) to perform image reproduction between different canvases, which is declared as follows:

void _fastcall copyrect (const windows::trect &&dest, Tcanvas*canvas, const windows::trect &&source);

Copies the parameter canvas the specified source canvas rectangular area source to the dest rectangular area of the target canvas. Using this method, and then through a certain algorithm, can realize the "Venetian blinds" stunt display.

Add the following code to the Button2 onclick event:

void _fastcall Tform1::button2click (tobject *sender)
{
int inum,icount,i,j;
Graphics::tbitmap *pbitmap = new Graphics::tbitmap ();
Pbitmap->height = image1->height;
Pbitmap->width = image1->width;
Inum = 16; This is the number of leaves in the blinds.
icount = pbitmap->height/inum;
for (i = 1; i < icount; i++)
for (j = 0; J <= Inum; j + +) {
Pbitmap->canvas->copyrect (Rect (0,icount*j + i-1, pbitmap->width,icount*j + i), Image1->canvas, Rect (0, Icount*j + i-1,pbitmap->width, icount*j + i));
Form1->canvas->draw (IMAGE1->LEFT,IMAGE1->TOP,PBITMAP);
}
Delete Pbitmap;
}

According to F9 run the above program, you can get the desired "venetian blinds" effect.

Image control also provides a number of other useful properties and methods, you can make full use of C + + Builder Help, mastered these properties and methods, and then use some program algorithms, you can freely write a variety of image stunt display program. In our application development, we can add these image stunt shows to add some luster to our application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.