Pixel operations of 24-Bit Bitmap in 32bpp window mode (2)

Source: Internet
Author: User

when the logic of the ranging scroll is almost written, it is found that the previously written bitmap has some problems with the Code in the display table, therefore, a function is rewritten to get a map directly on bitmap24_ptr Based on the surface size and Input coordinates. The complete code is provided first:

Int pickbitmap (lpdirectdrawsurface7 lpdds, bitmap24_ptr bitmap, long ddswidth, long ddsheight, long CX, long CY) <br/>{< br/> long bitmapwidth = Bitmap-> infoheader. biwidth; <br/> long bitmapheight = Bitmap-> infoheader. biheight; </P> <p> ddsurfacedesc2 ddsd; <br/> ddraw_init_struct (ddsd); <br/> lpdds-> lock (null, & ddsd, expires | ddlock_wait, null); <br/> int mempitch = ddsd. lpitch; <br/> uchar * ddsbuffer = (uchar *) (ddsd. lpsurface); </P> <p> for (long DY = 0, by = Cy; dy <ddsheight; ++ dy, ++) <br/> {<br/> memcpy (ddsbuffer + dy * mempitch, bitmap-> buffer + cx * 4 + by * bitmapwidth * 4, 4 * ddswidth ); <br/>}</P> <p> // displaymemory (ddsbuffer, mempitch * ddsheight); </P> <p> lpdds-> unlock (null ); </P> <p> return 1; <br/>}

This function was called to complete the unit test for one afternoon ~ Ah, there is no way to achieve low IQ.

This is also the first debugging of large-scale memory content after I switched to C/C ++. I still don't know what tools are available, so I wrote a plug-in first, the displaymemory function annotated in the above Code. The Code is as follows:

Char hextable [16] = {'0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F '}; </P> <p> void displaymemory (uchar * buffer, Long SIZE) <br/>{< br/> char * MSG = (char *) malloc (size * 3 + 1); </P> <p> for (long I = 0; I <size; ++ I) <br/>{< br/> char C1, C2, C3; <br/> C1 = hextable [(INT) (buffer [I])/16]; <br/> C2 = hextable [(INT) (buffer [I]) % 16]; <br/> C3 = ''; <br/> MSG [I * 3] = C1; <br/> MSG [I * 3 + 1] = c2; <br/> MSG [I * 3 + 2] = C3; <br/>}< br/> MSG [size * 3] = '/0 '; </P> <p> MessageBox (null, MSG, "Memory", mb_ OK); </P> <p> free (MSG); <br/>}

After the problem is solved, you can have a good sleep.

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.