Each time you resize the window, you'll see the captured screenshot displayed in the client area. Open the GDI_CapturingAnImage.cpp source code file in your new project, and replace its contents with the listing below. It's important to name the new project GDI_CapturingAnImage so that the code listing below will compile (for example, it includes GDI_CapturingAnImage.h, which will exist in your new project if you name it as suggested). To try out the code example, begin by creating a new project in Visual Studio based on the Windows Desktop Application project template. This section contains a code example that captures an image of the entire desktop, scales it down to the current window size, and then saves it to a file (as well as displaying it in the client area). To redisplay the image, call BitBlt a second time, specifying the compatible DC as the source DC and a window (or printer) DC as the target DC. In this case, the target DC is the compatible DC, so when BitBlt completes the transfer, the image has been stored in memory. Instead, BitBlt receives handles that identify two device contexts and copies the bitmap data from a bitmap selected into the source DC into a bitmap selected into the target DC. However, the two arguments to this function are not bitmap handles. This function performs a bit block transfer that is, it copies data from a source bitmap into a destination bitmap. After you create a compatible DC, you create a bitmap with the appropriate dimensions by calling the CreateCompatibleBitmap function and then select it into this device context by calling the SelectObject function.Īfter the compatible device context is created and the appropriate bitmap has been selected into it, you can capture the image. To store an image temporarily, your application must call CreateCompatibleDC to create a DC that is compatible with the current window DC. Later, when the user selects the normal view, the application must replace the zoomed image with a copy of the normal view that it temporarily saved. For example, when you scale or zoom a picture created in a drawing application, the application must temporarily save the normal view of the image and display the zoomed view. In some cases, you may want your application to capture images and store them only temporarily. The system automatically deletes the resource when its process terminates, however, calling the appropriate function saves memory and decreases the size of the process's working set.You can use a bitmap to capture an image, and you can store the captured image in memory, display it at a different location in your application's window, or display it in another window. When you are finished using the resource, you can release its associated memory by calling one of the functions in the following table. To get extended error information, call GetLastError. If the function fails, the return value is NULL. If the function succeeds, the return value is the handle to the newly created image. If the resource contains multiple images, the function uses the size of the first image. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size. Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are set to zero. This flag is only valid if uType is IMAGE_BITMAP. Otherwise, the bitmap image is created as a device-dependent bitmap. If this is set and a new bitmap is created, the bitmap is created as a DIB section. If this flag is not specified, a new object is always created. Returns the original hImage if it satisfies the criteria for the copy-that is, correct dimensions and color depth-in which case the LR_COPYDELETEORG flag is ignored. This will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by LoadImage with the LR_SHARED flag. If this flag is set, CopyImage uses the size in the resource file closest to the desired size. Without this flag, CopyImage stretches the original image to the new size. This is useful for creating a different-sized copy when the resource file contains multiple sizes of the resource. Tries to reload an icon or cursor resource from the original resource file rather than simply copying the current image. Valueĭeletes the original image after creating the copy. This parameter can be one or more of the following values. If this is zero, then the returned image will have the same height as the original hImage. The desired height, in pixels, of the image. If this is zero, then the returned image will have the same width as the original hImage. The desired width, in pixels, of the image. This parameter can be one of the following values. If necessary, the function stretches the bits to fit the desired size of the new image. Creates a new image (icon, cursor, or bitmap) and copies the attributes of the specified image to the new one.
0 Comments
Leave a Reply. |