1. Bitmap-grating image-distortion of Scaling
Meta File -- vector image -- Scaling without distortion
Ii. Some functions:
1. bitblt (bit bits)
Directly copy bitmap pixels.
2. bool CDC: stretchblt (int x, int y, int nwidth, int nheight, CDC * psrcdc, int xsrc, int ysrc, int nscwidth, int nscheight, DWORD dwrop );
It can be scaled or flipped.
Flip method: X indicates the X coordinate of the destination, nwidth indicates the destination width, positive indicates the right, and negative indicates the left. The Source width is different from the target width, that is, the Source width is flipped. Y coordinates are the same.
The scaling image of the stretchblt function is distorted. You can use the setstretchbltmode method to control the distortion.
Replication mode: dwdrop. This is actually a logical operation between the source device, the target device, and the image painter.
3. bool CDC: patblt (int x, int y, int nwidth, int nheight, dworddwdrop );
Block Transfer
This function is actually used to remove the source device from the stretchblt. It is only a logical operation between the target device and the image brush.
3. the GDI bitmap object is sometimes referred to as a device-related bitmap or DDB.
DDB depends on a specific device. It can only exist in memory (video memory or system memory). The color mode must be consistent with the specific output device and use the system color palette. Generally, only DDB bitmaps with relatively simple colors can be loaded. For color-rich bitmaps, dib must be used for long-term storage.
DDB is stored in the GDI mode and referenced by the digital handle of the application software. For example, hbitmap;
Create DDB to obtain the handle hbitmap = greatebitmap (...); // allocate and initialize some memory in the GDI memory to store bitmap information and bitmap information. The application cannot directly access the memory. Bitmap is irrelevant to the device description table.
Generally, greatebitmap is used only when a monochrome bitmap is created. In more cases, createcompatiblebitmap is used to simplify the problem.
Hbitmap = createcompatiblebitmap (HDC, CX, CY) to create device-compatible bitmaps.
There is also a function for creating DDB hbitmap = createbitmapindirect (& Bitmap)
You can also set the bitmap bit information setbitmapbits (hbitmap, cbytes, & bits) after creating a bitmap; // It is generally only used to set a monochrome. For example, it is used for writing.
Another method to obtain the DDB handle is hbitmap = loadbitmap (...); // compatible with the video display.
Clear memory: deleteobject (hbitmap );
Iv. memory device description
HDC hdcmem = createcompatibledc (HDC); // create a memory device description table compatible with HDC. If HDC is null, create a memory device description table compatible with the video display.
SelectObject (hdcmem, hbitmap); // select DDB into the device description table. SelectObject takes effect only when the selected bitmap is monochrome or has the same color structure as the compatible device. In fact, creating a description table for compatible devices is to set the same color structure.
Deletedc (hdcmem); // clear.
5. gettextextentpoint: determines the size (range) of a string ). In the Win32 environment, it is best to use gettextextentpoint32, which provides more accurate calculation results.
Write on the device and paste it in the customer area:
case WM_CREATE: hdc = GetDC (hwnd) ; hdcMem = CreateCompatibleDC (hdc) ; GetTextExtentPoint32 (hdc, szText, lstrlen (szText), &size) ; cxBitmap = size.cx ; cyBitmap = size.cy ; hBitmap = CreateCompatibleBitmap (hdc, cxBitmap, cyBitmap) ; ReleaseDC (hwnd, hdc) ; SelectObject (hdcMem, hBitmap) ; TextOut (hdcMem, 0, 0, szText, lstrlen (szText)) ; return 0 ;case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; switch (iSize) { case IDM_BIG: StretchBlt (hdc, 0, 0, cxClient, cyClient, hdcMem, 0, 0, cxBitmap, cyBitmap, SRCCOPY) ; break ; case IDM_SMALL: for (y = 0 ; y < cyClient ; y += cyBitmap) for (x = 0 ; x < cxClient ; x += cxBitmap) { BitBlt (hdc, x, y, cxBitmap, cyBitmap, hdcMem, 0, 0, SRCCOPY) ; } break ; } EndPaint (hwnd, &ps) ; return 0 ;
6. GetObject (byval hobject as long, byval ncount as long, lpobject as any) gets a structure that describes the specified object. For example, obtain the hbitmap size. For different objects, such as bitmap and image painter, the returned struct is different.
7. Mask.
The essence of the mask is to copy the source DC to the Target DC using parameters such as srccopy, srcand... And bitblt.
Principle: The source DC contains a white or black bitmap.
Example:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hBitmapImag, hBitmapMask ;
static HINSTANCE hInstance ;
static int cxClient, cyClient, cxBitmap, cyBitmap ;
BITMAP bitmap ;
HDC hdc, hdcMemImag, hdcMemMask ;
int x, y ;
PAINTSTRUCT ps ;
switch (message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
// Load the original image and get its size
hBitmapImag = LoadBitmap (hInstance, TEXT ("Matthew")) ;
GetObject (hBitmapImag, sizeof (BITMAP), &bitmap) ;
cxBitmap = bitmap.bmWidth ;
cyBitmap = bitmap.bmHeight ;
// Select the original image into a memory DC
hdcMemImag = CreateCompatibleDC (NULL) ;
SelectObject (hdcMemImag, hBitmapImag) ;
// Create the monochrome mask bitmap and memory DC
hBitmapMask = CreateBitmap (cxBitmap, cyBitmap, 1, 1, NULL) ;
hdcMemMask = CreateCompatibleDC (NULL) ;
SelectObject (hdcMemMask, hBitmapMask) ;
// Color the mask bitmap black with a white ellipse
SelectObject (hdcMemMask, GetStockObject (BLACK_BRUSH)) ;
Rectangle (hdcMemMask, 0, 0, cxBitmap, cyBitmap) ;
SelectObject (hdcMemMask, GetStockObject (WHITE_BRUSH)) ;
Ellipse (hdcMemMask, 0, 0, cxBitmap, cyBitmap) ;
// Mask the original image
BitBlt (hdcMemImag, 0, 0, cxBitmap, cyBitmap,
hdcMemMask, 0, 0, SRCAND) ;
DeleteDC (hdcMemImag) ;
DeleteDC (hdcMemMask) ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
// Select bitmaps into memory DCs
hdcMemImag = CreateCompatibleDC (hdc) ;
SelectObject (hdcMemImag, hBitmapImag) ;
hdcMemMask = CreateCompatibleDC (hdc) ;
SelectObject (hdcMemMask, hBitmapMask) ;
// Center image
x = (cxClient - cxBitmap) / 2 ;
y = (cyClient - cyBitmap) / 2 ;
// Do the bitblts
BitBlt (hdc, x, y, cxBitmap, cyBitmap, hdcMemMask, 0, 0, 0x220326) ;
BitBlt (hdc, x, y, cxBitmap, cyBitmap, hdcMemImag, 0, 0, SRCPAINT) ;
DeleteDC (hdcMemImag) ;
DeleteDC (hdcMemMask) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
DeleteObject (hBitmapImag) ;
DeleteObject (hBitmapMask) ;
DeleteDC(mydc);
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
8. Create a bitmap and operate it:
HDC = getdc (hwnd );
Hdcmem = createcompatibledc (HDC );
Hbitmap = createcompatiblebitmap (HDC, cxtotal, cytotal );
Releasedc (hwnd, HDC );
SelectObject (hdcmem, hbitmap );
Rectangle (hdcmem,-1,-1, cxtotal + 1, cytotal + 1 );
Hbrush = createhatchbrush (hs_diagcross, 0l );
SelectObject (hdcmem, hbrush );
Setbkcolor (hdcmem, RGB (255, 0,255 ));
Ellipse (hdcmem, cxmove, cymove, cxtotal-cxmove, cytotal-cymove );
Deletedc (hdcmem );
Deleteobject (hbrush );
IX,
Hwnd = getdesktopwindow () // obtain the desktop window handle
Lockwindowupdate (hwnd) // Disable Windows from being refreshed by other programs
Lockwindowupdate (null); // cancel prohibition
Getdcex (hwnd, null, dcx_cache | dcx_lockwindowupdate );