Method for displaying and processing images in the VC

xiaoxiao2021-03-06  55

Method 1: This method is a function library of a read bitmap on a book related to a classic VC image processing.

When there is no such a library, there is not much practical value. This method is directly used by reading and displaying a library of BMP pictures. First, you should get the location where you want to display the area: CWnd * PWnd = getdlgitem (IDC_BMP); Rect Rect; PWND-> getClientRect (& Rect); CDC * PDC = PWND -> getdc (); then call the function library // Get the width INT CXDIB = (int) :: Dibwidth (LPDIB); // Get the height of the DIB image INT CYDIB = (int):: DibHeight (LPDIB); Finally, call the library // Call PaintDIB Outlet Images :: PainTDIB (PDC-> M_HDC, & Rect, M_HDIB, & RCDIB, NULL); the most release resource ReleaseDC (PDC);

-------------------------------------------------- ------------------------------

Method 2: This method is to draw directly on the screen, of course, because it is a little painting, so the speed will be slow. First, you must get the location where you want to display the area: CWND * PWND = getdlgitem (IDC_BMP); CDC * PDC = PWND-> getdc (); then PDC-> setpixel (IW, IH, RGB (R, G, B)); most To release the resource ReleaseDC (PDC);

-------------------------------------------------- ----------------------------------

Method 3: This method is to open a space in memory, and then write data in memory with setpixel, and finally display data over again on the screen. Of course, from the description, this method is faster than the law 2, but because of the writing data of a point, it will be slow.

First, you should get the location where you want to display the area: CWND * PWND = getDLGITEM (IDC_BMP); CDC * PDC = PWND-> getdc (); then CDC MEMDC; cbitmap m_bitmap, * m_poldbitmap;

memdc.CreateCompatibleDC (pDC); m_bitmap.CreateCompatibleBitmap (pDC, lWidth, lHeight); m_pOldBitmap = memdc.SelectObject (& m_bitmap); then, can change the data in the memory memdc.SetPixel (iw, lHeight-ih, RGB (nrgb NRGB, NRGB); display the results PDC-> Stretchblt (0, 0, Rect.right-Rect.Left, Rect.Bottom-Rect.top, & MEMDC, 0, 0, LWIDTH, LHEIGHT, SRCCOPY); Release resource MEMDC.SELECTOBJECT (m_poldbitmap); m_bitmap.deleteObject (); ReleaseDC (PDC);

-------------------------------------------------- ---------------------------------

Law 4: This method is quite good, be sure to take a look :) This should be a method than the method 2 and the method 3, because it is directly assigned a region directly, directly with the method of operating the memory area. Operate it, wait for the operation to write on the screen again. First, to obtain a display area CWnd * pWnd = GetDlgItem (IDC_IMG); CDC * theDC = pWnd-> GetDC (); CRect clientRect; pWnd-> GetClientRect (clientRect); then, write the headers BITMAPINFOHEADER bmiHeader; bmiHeader.biSize = sizeof (BITMAPINFOHEADER); bmiHeader.biWidth = m_width; bmiHeader.biHeight = m_height; bmiHeader.biPlanes = 1; bmiHeader.biBitCount = 24; bmiHeader.biCompression = BI_RGB; bmiHeader.biSizeImage = 0; bmiHeader.biXPelsPerMeter = 0; bmiHeader.biYPelsPerMeter = 0; bmiheader.birrused = 0; bmiheader.birrimportant = 0; now you can display image data on the screen // now blast it to the cdc passed in. // Lines Returns the Number of line atually displayed int lines = StretchDIBits (theDC-> m_hDC, left, top, bmiHeader.biWidth, bmiHeader.biHeight, 0,0, bmiHeader.biWidth, bmiHeader.biHeight, tmp, (LPBITMAPINFO) & bmiHeader, DIB_RGB_COLORS, SRCCOPY); Note die, wherein the tmp The type is Byte *, that is, it is pointing to a memory zone, as long as the data placed in this memory area is the format of the data area in the BMP bitmap, it is possible. That is to say, each line element is a 32 bit (4 Byte) integer multiple. With this method, you can say that you can directly assign a memory area with a function of allocating a memory, and then use MEMCPY to copy the contents of a memory to another memory, and then processed, then display it.

Don't forget to release the resource ReleaseDC (THEDC);

-------------------------------------------------- ---------------------- In addition, get the CDC of the entire dialog, I am sorry, I don't know what CPAINTDC DC (this); cdc * hasDc = & dc ;

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

New Post(0)