Preliminary knowledge of Visual C + + 2005 Image programming

Source: Internet
Author: User
Tags array definition integer numbers

In the process of image processing, there are many aspects that require our mastery or attention. Here I first briefly introduce some basic and important knowledge.

1, Image processing system framework

A basic image processing system consists of 4 subsystems: Image input system, image output system (display), image storage System, image processing and analysis system.

Figure 1-1

2, the composition of the image

The image gives us the first intuitive feeling is some colorful dots, in the computer language, these points are called pixels. It is these pixels that come together to form a pair of beautiful pictures. So how do you combine this intuitive understanding with our computer programs? How do you represent these colorful dots in your computer? Understanding these 2 questions has a lot to do with the image processing behind us. The image can be a matrix, in the computer programming language, the best representation method is the array, the two-dimensional array. Keep each pixel of the image in one element of the array. This process is also known as Digital Image sampling: The digitization of the image represented by two-dimensional coordinate space.

3, the speed of image processing

In the process of image processing, there are a lot of mathematical calculations and loops. How to deal with these processes has a very important impact on the speed of image processing. The definition of the internal variables of the processing function also needs to be noted: for example, for commonly used variables, you can save them with static or global variables within the function, speeding up the speed. However, in large projects, excessive static, local variables will occupy more memory, while affecting the start speed of the program. So this requires us to weigh the actual situation. There are floating-point and integer numbers in mathematical calculations, and floating-point operations are very precise, but the computation speed is slightly slow, the integer operation is not error, and the computation speed is fast. Therefore, in the process of image processing, as far as possible, the use of integer operations, floating-point operations will be due to the computer's processor representation of a certain error.

When traversing the pixel of the image, there will be a lot of cyclic process, in the cycle, minimize the possible code such as variable definition, multiprocessor support for better addition and shift operations, reduce multiplication operations. Even if you can use assembly language for some common functions.

4, the efficiency of the map

Many novice image programming friends are almost always experiencing the problem of texture flicker. Our most common method is the double buffer map. Basic Code Snippets:

The PDC is the target window for the last image display DC,PMEMDC is a temporary DC in memory

CDC *PMEMDC = CreateCompatibleDC (PDC);

CBitmap Bitmap;

Width, height is the height and width of the target window that the image is last displayed

Bitmap. CreateCompatibleBitmap (PDC, Width, Height);

Pmemdc->selectobject (&BITMAP);

Then we can do whatever drawing we need on the PMEMDC, and then post it to the target window DC after we finish drawing it.

Pdc->bitblt (0, 0, Width, Height, PMEMDC, 0, 0, srccopy);

Pmemdc->deletedc ();

In some cases we need to do a lot of texture, paste a lot of different small pictures, we need to pay attention to the call of the SelectObject function, the frequent invocation of this function to select a variety of different drawing properties will greatly reduce the speed of the program.

Avoid unnecessary redraw, and after you have finished drawing, you can suppress the system's paint process to avoid flicker: Returns true directly in the WM_ERASEBKGND message function and no longer continues to call the base class's message handler function. When you need to redraw the exact update, instead of blindly painting all the content, such as calling InvalidateRect to replace the transition of the invalidate call process. Because it takes a lot less time to compute the rect of the content than to repaint it.

In the process of image processing, there are many aspects that need our special attention, I will do further discussion in the later part.

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.