Graphic stunts in Visual C ++

xiaoxiao2021-03-05  28

Article Title: Visual C Graphic Stunt Care: Zhao Minzhi's original: Loose_Went Release Type: Loose_WENT Release Type: Reprinted Release Date: 2004-01-08 Today Views: 1 Total View: 2324

With the multimedia of computer information and the multimedia, in many learning software, game software, and multimedia courseware software, various graphic display skills, such as graphics, staggered, raindrops, 100-page window, building blocks random Stacking and other display modes. This makes the picture more lively, and it is more attractive to the user, and lays the foundation for better playing software. This article discusses some of the principles and specific methods of implementing graphics in Visual C 6.0. Basic Principles In Visual C 6.0, the method and procedures of the display bitmap are as follows: 1. Display the bitmap in the program resource (all the data of the bitmap exists in the executable) (1) loading from the resource Bitmap ● Define bitmap object data member cBitmap m_bitmap; ● Call the CBITMAP member function loadbitmap (), such as m_bitmap.loadbitmap (idb_bitmap1); ● Parameters that pass to Loadbitmap are generated in the graphic editor or from bitmap files The identifier given when introducing. (2) Generate a memory device contextual object CDC MEMDC; MEMDC.CREATECMMPALED (NULL); MEMDC.SELECTOBJECT (& m_bitmap); (3) Display bitmap cclientdc clientdc (this); Bitmap BM; m_bitmap.getObject SizeOf (BM), & BM); ClientDC.bitblt (x, y, // target device logic horizontal, longitudinal coordinate BM.BMWIDTH, BM.BMHEIGHT, / / ​​shows pixel wide, height & memdc, // to be displayed The device contextual objects of the map data 0, 0, // Source Data are horizontal, longitudinal data SRCCOPY); // bit operation mode This method shows the bitmap speed, but not very flexible, and will increase the executable . 2. Display a bitmap of a separate file mode (all data in the bitmap independently of the executable) hbitmap * hbitmap; // Define bitmap object handle Bitmap BM; CDC MEMDC; CClientDC ClientDC (this); Memdc.createCompatibleDC (& Clientdc) Hbitmap = (hbitmap *) :: loadImage (AFXGetInstanceHandle (), // acquire application handle "demo1.bmp", // bitmap file name image_bitmap, // type Windows bitmap 0,0, lr_loadfromfile; / / From the file, click the diagram data MEMDC.SelectObject (HbitMap); :: getObject (hbitmap, sizeof (bm), & bm); clientdc.bitblt (...) // Use the format with method to display bitmap speed Compared with the previous one, the flexibility is large, and the bitmap file can be changed, without removing the source program, also reduces the size of the executable file. Implementation Method The following describes the specific implementation principles and methods of various graphic display skills.

The implementation of all the program algorithms in all program algorithms can be placed in the view class (CVIEW, also visible to other classes in other classes), and it is necessary to perform the following related operations: increase the following member variable: Bitmap m_bm; // Save The wide, height of the bitmap hbitmap * m_hbitmap; // Save bitmap data handle CDC M_MEMDC; // Memory device situations in the class constructor Add to code: m_memdc.createcompatibledc (null); // Generate memory device situation Object m_hbitmap = (hbitmap *) :: loadimage (// loaded from the file AfxGetInstanceHandle (), "demo1.bmp", image_bitmap, 0, 0, lr_loadfromfile; m_memdc.selectObject (m_hbitmap); // Bitmap Select memory device situations :: getObject (m_hbitmap, sizeof (m_hbitmap, sizeof); 1. Level interlaced effect principle: split the bitmap data in memory device situations (such as MEMDC), dual scan There are two parts of the line, and the odd number of scanned lines are moved upward, and the even stroke scan line moves upwards, and both simultaneously. The effect on the screen is the more light grid graphics that appear on both ends, gradually approaching, until the entire bitmap is fully clear. The principle of the realization of vertical interleaved effects. Program algorithm: INT I, J; for (i = 0; i <= m_bm.bmheight; i = 2) {j = i; while (j> 0) {clientdc.stretchblt (/ odd number, from top to bottom 0 , J-1, // Target device logic horizontal, ordinate m_bm.bmwidth, 1, // Display bitmap pixel wide, height & m_memdc, // source bit map device context object 0, m_bm.bmheight- (ij-1 ), // source bit map, longitudinal coordinate m_bm.bmwidth, 1, // source bit map of pixel wide, high SRCCOPY); clientdc.stretchblt (// even, by bottom to upper 0, m_bm.bmheight- J, // Target device logic horizontally, ordinate m_bm.bmwidth, 1, // Display bitmap pixel wide, height & m_memdc, // source bit map device context object 0, Ij, // source bit map start horizontal , Longitudinal coordinate m_bm.bmwidth, 1, // source bit map pixel wide, high SRCCOPY; J- = 2;} // while (j> 0) SLEEP (10);} // for (i = 0; I <= m_bm.bmheight; i = 2) 2. Principle of raindrops: the last scan line of the memory device contextual object (such as MEMDC), sequentially display bitmap from the target device (such as ClientDC) The first scan line is located to the last level and retain the trajectory left when the scan line moves on the screen. Then, the diagram of the diagram data of the MEMDC mediate data is then moved to the position where the first scan line of the target device (such as ClientDC) is displayed to the position of the position of the bitmap. The remaining scan lines are pushed accordingly.

Program algorithm: int I, j; for (i = 0; i <= m_bm.bmheight; i ) {for (j = 0; j <= m_bm.bmHeight-i; j ) clientdc.stretchblt (0, J, / / Target device logic horizontally, ordinate m_bm.bmwidth, 1, // Display bitmap pixel wide, height & m_memdc, // source bit map device context object 0, m_bm.bmHeight-i, // source bit map start The pixel wide, high-level SRCCOPY of the horizontal, ordinate m_bm.bmwidth, 1, // source bit map; SLEEP (20);} // for (i = 0; i <= m_bm.bmheight; i ) 3. Blond effect Principle: Divide the bitmap data in the memory device context object (such as MEMDC) into several groups, then move from the first group to the last set, and move the first scan line to the target device in each group, respectively. ClientDC) The corresponding position of the bitmap is to be displayed, and the second scan line in each group is moved second, then the third, fourth scan lines. Program algorithm: INT I, Stepi, J; Stepi = m_bm.bmHeight / 10; for (i = 0; i <= stepi; i ) {for (j = 0; j <10; J ) Clientdc.stretchblt (0, J * STEPI I, / / ​​Target device logic horizontal, ordinate m_bm.bmwidth, 1, // Display bitmap pixel wide, height & m_memdc, // source bit map device contextual object 0, J * Stepi i, / / SLEP (20);} // for (i = 0; i <= step); SLEEP (20);} // for (i = 0; i <= step; i ) 4. Random block effect principle: divide the bitmap data in the memory device situation object (such as MEMDC) into a vertical and horizontal tens of part of the total group of data, and then randomly remove a group of this hundred groups of data display to the target The device (such as ClientDC) is waiting to display the corresponding position of the bitmap, so repeatedly until all 100 sets of data are shown.

转载请注明原文地址:https://www.9cbs.com/read-35097.html

New Post(0)