Software automated test screenshot method and terminal

By obtaining the target window handle and device context handle, creating a memory device context, configuring the bitmap object, and processing the image data, the problem of screenshot failure caused by invalid mouse click operations was solved, and efficient and stable software automated test screenshots were achieved.

CN122346340APending Publication Date: 2026-07-07FUJIAN TQ DIGITAL
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510021917.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-07
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

In existing methods for taking screenshots in automated software testing, mouse clicks may fail, leading to screenshot failures. This affects the stability and efficiency of the testing process and is time-consuming.

Method used

By obtaining the target window handle and its device context handle, a memory device context is created, bitmap objects are configured, and image data is processed. This avoids flickering and performance issues caused by direct screen manipulation, optimizes resource utilization, and ensures the accuracy and stability of screenshots.

Benefits of technology

It improves the quality of screenshots and the stability of the testing process, reduces system resource leaks, and ensures the reliability and efficiency of testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122346340A_ABST
    Figure CN122346340A_ABST
Patent Text Reader

Abstract

The application discloses a software automatic test screenshot method and a terminal, which comprises the following steps: obtaining a target window handle and a corresponding device environment handle in response to a screenshot operation; creating a memory device context environment according to the device environment handle and pre-allocating memory space for the memory device context environment; obtaining device monitor information according to the device environment handle; determining the size and resolution of a bitmap using an intelligent computing model according to the device monitor information and expected use information of the screenshot; creating a bitmap object according to the size and resolution of the bitmap and configuring parameters for the bitmap object; storing the bitmap object to the memory device context environment; copying image data corresponding to the device environment handle to the bitmap object and processing the image data in the bitmap object; exporting and saving the processed image data from the bitmap object; cleaning and releasing system resources; optimizing the screenshot process; improving the screenshot quality; ensuring the test stability and reliability; and improving the test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software automated testing technology, and in particular to a method and terminal for taking screenshots during software automated testing. Background Technology

[0002] In the field of software automation testing, screenshotting is a crucial function. A common method for taking screenshots is to use `win32api.mouse_event` to simulate clicking the screenshot button. However, this traditional method has many drawbacks. The most prominent problem is that the mouse click operation may fail, directly leading to screenshot failure. In automated testing workflows, the testing process is often time-consuming; for example, the average duration of a typical automated test workflow is long, and feedback is not timely or efficient. Screenshot failures severely disrupt the normal progress of the testing process, reducing testing efficiency and increasing the time and manpower costs required for testing. Therefore, there is an urgent need for a software automation testing screenshot method and terminal that can solve the above problems. Summary of the Invention

[0003] The technical problem to be solved by this invention is to provide a software automated test screenshot method and terminal, which can improve testing efficiency, improve the quality of screenshot images, and ensure the stability and reliability of the testing process.

[0004] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: A method for taking screenshots during software automation testing, comprising the following steps: S1. In response to the screenshot operation, obtain the target window handle and its corresponding device context handle, create a memory device context based on the device context handle, and pre-allocate memory space for the memory device context. S2. Obtain device monitor information based on the device environment handle; determine the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot; create a bitmap object based on the size and resolution of the bitmap and configure parameters for the bitmap object; and store the bitmap object in the memory device context. S3. Copy the image data corresponding to the device environment handle to the bitmap object, process the image data in the bitmap object, export and save the processed image data from the bitmap object, and clean up and release system resources.

[0005] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows: A software automated test screenshot terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the various steps of the aforementioned software automated test screenshot method.

[0006] The beneficial effects of this invention are as follows: This invention provides a software automated testing screenshot method and terminal. In response to a screenshot operation, it obtains the target window handle and its corresponding device context handle to understand the display attributes of the target window, laying the foundation for subsequent creation of a memory device context and bitmap object. A memory device context is created based on the device context handle to facilitate graphics drawing and screenshot operations in memory, avoiding flickering and performance issues caused by direct screen operations. Memory space is pre-allocated for the memory device context to ensure appropriate memory resource allocation and optimize resource utilization. Device monitor information is obtained based on the device context handle. Based on the device monitor information and the intended use of the screenshot, an intelligent computing model is used to determine the size and resolution of the bitmap. Based on the size and resolution of the bitmap... A bitmap object is created and its parameters are configured. By accurately acquiring and utilizing device monitor information, the size and resolution of the bitmap are determined, enabling screenshots to better reproduce various details and features of the original image, improving image quality and providing more accurate data support for test analysis. The image data corresponding to the device environment handle is copied to the bitmap object, and the image data in the bitmap object is processed to improve image clarity and smoothness, optimize the visual effect of the image, making it clearer and more aesthetically pleasing, facilitating subsequent test analysis and report generation. The processed image data is exported from the bitmap object and saved, cleaning up and releasing system resources to avoid resource leaks that could lead to system performance degradation or other program operation problems, ensuring that the next screenshot operation can proceed normally and guaranteeing the stability and reliability of the test process. Attached Figure Description

[0007] Figure 1 This is a flowchart of a software automated testing screenshot method according to an embodiment of the present invention; Figure 2 This is a schematic diagram of a software automated testing screenshot terminal according to an embodiment of the present invention; Label Explanation: 1. A software automation testing screenshot terminal; 2. Memory; 3. Processor. Detailed Implementation

[0008] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.

[0009] Please refer to Figure 1This invention provides a method for taking screenshots during automated software testing, comprising the following steps: S1. In response to the screenshot operation, obtain the target window handle and its corresponding device context handle, create a memory device context based on the device context handle, and pre-allocate memory space for the memory device context. S2. Obtain device monitor information based on the device environment handle; determine the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot; create a bitmap object based on the size and resolution of the bitmap and configure parameters for the bitmap object; and store the bitmap object in the memory device context. S3. Copy the image data corresponding to the device environment handle to the bitmap object, process the image data in the bitmap object, export and save the processed image data from the bitmap object, and clean up and release system resources.

[0010] As can be seen from the above description, the beneficial effects of the present invention are as follows: By responding to a screenshot operation, the target window handle and its corresponding device context handle are obtained, so as to know the display attributes of the target window, laying the foundation for the subsequent creation of a memory device context and bitmap object. A memory device context is created based on the device context handle to facilitate graphics drawing and screenshot operations in memory, avoiding flickering and performance problems caused by direct operation on the screen. Memory space is pre-allocated for the memory device context to ensure appropriate memory resource allocation and optimize resource utilization. Device monitor information is obtained based on the device context handle. Based on the device monitor information and the intended use information of the screenshot, an intelligent computing model is used to determine the size and resolution of the bitmap. A bitmap object is created based on the size and resolution of the bitmap. The parameters for the bitmap object are configured. By accurately acquiring and utilizing device monitor information, the size and resolution of the bitmap are determined, enabling the screenshot to better reproduce various details and features of the original image, improving the image quality and providing more accurate data support for test analysis. The image data corresponding to the device environment handle is copied to the bitmap object, and the image data in the bitmap object is processed to improve the image clarity and smoothness, optimize the visual effect of the image, making the image clearer and more beautiful, facilitating subsequent test analysis and report generation. The processed image data is exported from the bitmap object and saved, cleaning up and releasing system resources to avoid resource leaks that could lead to system performance degradation or other program operation problems, so that the next screenshot operation can be performed normally, ensuring the stability and reliability of the test process.

[0011] Furthermore, obtaining the target window handle and its corresponding device context handle includes: Call the window enumeration function and traverse all windows according to the preset window title or class name matching algorithm. If an error occurs during the window search process, record the error information and traverse the search again or provide an error message until the target window is found. Obtain the target window handle corresponding to the target window, and call the device context function to obtain the corresponding device environment handle based on the target window handle. Check the obtained device environment handle. If the check result indicates that the acquisition of device environment has failed, release the obtained device environment handle and reacquire the device environment handle.

[0012] As described above, by calling the window enumeration function to traverse and search all windows according to the preset window title or class name matching algorithm, the target window is accurately located, avoiding inaccurate or failed screenshots due to window recognition errors. An error handling mechanism is also provided to improve program stability. By obtaining the target window handle and its corresponding device context handle, and checking the device context handle, system resources are effectively managed, ensuring the validity of the device context handle and avoiding rendering problems caused by invalid handles.

[0013] Furthermore, the step of pre-allocating memory space for the memory device context includes: Based on the obtained total system memory capacity and current system memory usage, the remaining system memory is determined, and the resolution and color depth of the screenshot are determined based on the size of the target window and the intended use of the screenshot. The amount of memory required for taking a screenshot is calculated using a preset memory allocation algorithm based on the remaining system memory, the resolution, and the color depth, and memory space is pre-allocated to the memory device context environment based on the amount of memory required for the screenshot.

[0014] As described above, by determining the current system memory resource status and the amount of memory required for screenshots, memory space is dynamically pre-allocated for the memory device context, thus optimizing memory management. This ensures that appropriate memory resources are allocated for screenshot operations, avoiding screenshot failures due to insufficient memory allocation or resource waste caused by excessive memory allocation. Furthermore, reasonable memory allocation can better balance the resource requirements of screenshot tasks and other running programs, improving the overall performance and stability of the system.

[0015] Furthermore, the step of determining the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot includes: When the intelligent computing model receives the device monitor information and the intended use information of the screenshot, it determines the size of the bitmap based on the physical size and pixel density in the device monitor information, determines the resolution of the bitmap based on the refresh rate in the device monitor information, and adjusts the size and resolution of the bitmap based on the intended use information of the screenshot.

[0016] As described above, the size and resolution of the bitmap are determined based on the device monitor information, and the size and resolution of the bitmap are adjusted according to the intended use of the screenshot. While ensuring clarity, the resolution is appropriately reduced to reduce storage space and data processing volume, so that the screenshot can meet various needs while optimizing system resource utilization and operational efficiency.

[0017] Furthermore, the step of processing the image data in the bitmap object, and exporting and saving the processed image data from the bitmap object, includes: Create an image data copy, detect noise points in the image data copy using an image analysis algorithm, remove noise using a filtering algorithm, adjust the brightness and contrast distribution of the image data copy according to a preset target value, and update the image data of the bitmap object with the adjusted image data copy; Set the image data saving parameters, use an image encoding library to convert the image data into file data in a preset format, and export and save the file data according to the preset save path.

[0018] As described above, by creating and processing a copy of the image data, irreversible damage to the original image data can be avoided. The adjusted copy of the image data is then updated to the image data of the bitmap object, making the image data of the bitmap object clearer and more aesthetically pleasing, which facilitates subsequent testing, analysis, and report generation. The image data saving parameters are set to balance the relationship between file size and image quality, ensuring image clarity.

[0019] Please refer to Figure 2 Another embodiment of the present invention provides a software automated test screenshot terminal, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the various steps of the above-described software automated test screenshot method.

[0020] The software automated testing screenshot method and terminal described above are applicable to automated testing process screenshots, improving testing efficiency and screenshot quality, and ensuring the stability and reliability of the testing process. The following detailed implementation methods illustrate these methods: Please refer to Figure 1 Embodiment 1 of the present invention is: a method for taking screenshots during automated software testing, comprising the following steps: S1. In response to the screenshot operation, obtain the target window handle and its corresponding device context handle, create a memory device context based on the device context handle, and pre-allocate memory space for the memory device context.

[0021] In this embodiment, in response to a screenshot operation, the target window handle and its corresponding device context handle are obtained to understand the display attributes of the target window. This lays the foundation for the subsequent creation of a memory device context and bitmap object. A memory device context is created based on the device context handle to facilitate graphics drawing and screenshot operations in memory, avoiding flickering and performance issues caused by direct screen operations. Memory space is pre-allocated for the memory device context to ensure appropriate memory resource allocation and optimize resource utilization. Prior to the screenshot operation, the process also includes importing necessary system libraries and modules, namely, importing operating system window management, graphics device interface (GDI), and memory management modules. System libraries related to image processing, such as dynamic link libraries like 'user32.dll' and 'gdi32.dll' in Windows systems, and the corresponding 'ctypes' library in Python for calling system functions; importing modules related to image and data processing, such as 'numpy' for processing image data arrays; defining variables and structures related to storing window handles, device context (DC) handles, memory device context handles, bitmap information structures, etc. For example, defining a structure to store monitor information such as the physical size of the display, refresh rate, and pixel density for later use when calculating bitmap space and performing image processing.

[0022] Furthermore, in this embodiment, obtaining the target window handle and its corresponding device context handle includes: calling a window enumeration function and traversing all windows according to a preset window title or class name matching algorithm; if an error occurs during the window search process, the error information is recorded and the search is repeated or an error message is provided until the target window is found. The window enumeration function is preferably the EnumWindows function. During the target window search process, the ctypes library is used to correctly set function parameters and determine the call, ensuring correct interaction with system functions and accurate location of the target window. This avoids inaccurate or failed screenshots due to window recognition errors. Errors during this process include insufficient permissions or insufficient system resources preventing the acquisition of the window list; an error handling mechanism is provided to improve program stability. The process also involves obtaining the target window handle corresponding to the target window and calling the device context handle based on the target window handle. The function retrieves the corresponding device context handle, checks the retrieved device context handle, and if the check indicates that the acquisition of the device context failed, it releases the retrieved device context handle and re-acquires it. This includes: using the acquired window handle as a parameter, calling the GetDC function (or a similar system function) to obtain the device context (DC) handle of the target window. This function returns a handle representing the window's device context, through which the program can access the window's display properties and perform graphical operations; and checking the validity of the acquired device context handle. If the handle is invalid (return value 'NULL'), it indicates that the acquisition of the device context failed, and the program should take appropriate error recovery measures, such as releasing the acquired resources and retrying to acquire them, or deciding whether to terminate program execution based on the severity of the error, effectively managing system resources, ensuring the validity of the device context handle, and avoiding rendering problems caused by invalid handles.

[0023] Furthermore, in this embodiment, creating a memory device context environment includes: based on the obtained window device context handle, calling the 'GreateCompatibleDC' function to create a memory device context environment compatible with the specified device. This memory device context environment will be used for graphics drawing and screenshot operations in memory, avoiding flickering and performance issues that may occur when operating directly on the screen. The specified device is the display device associated with the obtained window, specifically including: 1. The display device logically associated with the target window. Once the device context handle of the target window is obtained, the specified device is the display device on which the target window is located, such as the computer monitor. This is because the window is presented on the display device, and the window device context handle is actually an identifier and operation interface associated with that display device. Through this handle, the system can identify the specific display device where the window is located, and thus create a compatible memory device context based on it. For example, in a multi-monitor computer system, multiple windows may be displayed on each monitor. When a screenshot operation is performed on a specific window, the obtained DC handle of that window clarifies the monitor to which it belongs. At this time, the specified device on which the memory device context is created is this specific monitor. 2. Memory device context that matches the characteristics of the display device. The purpose of creating a memory device context compatible with a specified device is to simulate the characteristics of that display device in memory for graphics drawing and screenshot operations. The specified device has specific display attributes, such as resolution (e.g., 1920×1080 pixels), color mode (e.g., true color 32-bit), pixel format (e.g., RGB or ARGB), and refresh rate (e.g., 60Hz). The memory device context needs to match these attributes in order to accurately process and store image data related to the window content on that display device in memory. For example, if the specified device has a high resolution, the created memory device context should also have the corresponding ability to process high-resolution image data to ensure that the screenshot can completely and accurately reflect the display effect of the window on the high-resolution display device.

[0024] Furthermore, in this embodiment, the factors influencing the creation of the memory device context include: 1. Diversity of display devices Different display devices may have different hardware characteristics and capabilities. For example, different brands and models of monitors may differ in color reproduction capabilities, pixel density, and maximum supported resolution. These characteristics of a specific device determine how to adapt to these differences when creating a memory device context environment in order to ensure the universality and accuracy of the screenshots.

[0025] For example, professional graphic design monitors may have higher color accuracy and a wider color gamut, while general office monitors may focus on cost and versatility. For different types of specific devices, the creation of memory device context environments needs to be adjusted accordingly to adapt to their display characteristics and ensure that the screenshot quality is not affected by the differences in display devices. 2. System resource and performance balance Considering the characteristics of a specific device is not only to ensure the accuracy of screenshots, but also to strike a balance between system resource utilization and performance. Creating a memory device context environment highly compatible with the specified device may consume certain system resources, such as memory space and computing resources. Therefore, during the creation process, it is necessary to reasonably configure the parameters of the memory device context environment according to the actual situation of the specified device and the current system resource status to avoid excessive resource consumption that could lead to a degraded system performance.

[0026] For example, in a resource-constrained system, if the resolution of the specified device is too high, some optimization strategies may be needed when creating the memory device context, such as appropriately reducing the image quality or using a more efficient compression format to store image data, in order to ensure that the overall performance of the system remains stable without affecting the basic screenshot function, and to avoid system lag or other program malfunctions caused by screenshot operations.

[0027] Furthermore, in this embodiment, the memory device context is closely related to the target window's device context, and the following relationships and associations exist: 1. Based on and extended Dependency: The creation of the memory device context is based on the obtained device context handle of the target window. The device context handle of the target window is a key identifier associated with the actual display device. It contains various attribute information of the window on the display device, such as display mode, resolution, color depth, etc. Through this handle, the `CreateCompatibleDC` function can obtain the necessary information related to the display of the target window, thereby creating a memory device context that is compatible with it. For example, the device context handle of the target window determines that the resolution of the display device where the window is located is 1920×1080 pixels, the color depth is 32-bit true color, etc. When creating the memory device context, the `CreateCompatibleDC` function will set the initial parameters of the memory environment according to this information so that it can adapt to the display characteristics of the target window, ensuring that subsequent graphics drawing and screenshot operations in memory match the presentation of the target window on the actual display device. 2. Functionality Expansion The memory device context extends the functionality of the target window device context. While the target window's device context is primarily used for graphics-related operations on the display device, the memory device context simulates a similar operating environment in memory. It allows programs to perform graphics drawing and processing in memory, avoiding flickering issues that may occur when operating directly on the screen. Furthermore, it provides a workspace independent of the screen display for screenshot operations, making the screenshot process more stable and controllable. For example, when performing complex graphics processing or screenshot operations, operating directly on the screen device context may cause screen flickering due to frequent graphics updates, affecting the user experience. The memory device context, however, can complete graphics drawing and screenshot-related calculations and processing in memory first, and then output the final result to the screen or save it as a file after the operation is complete, improving the efficiency and stability of the operation. It also provides more possibilities for further optimizing the screenshot process, such as preprocessing and optimizing images in memory before saving or displaying them. 3. Data Interaction and Collaboration Data Interaction Bridge: A data interaction bridge exists between the two. During the screenshot process, the image data in the target window device environment needs to be copied to the memory device context environment for processing and saving. For example, using the 'BitBlt' function (or a similar image copy function), the window content can be accurately copied to the bitmap object in the memory device context environment based on the image information in the target window device environment. This data interaction ensures that the screenshot can capture the accurate image content of the target window and can be further optimized and processed in the memory environment. At the same time, some configuration information and processing results in the memory device context environment may also be fed back to the target window device environment. For example, in some cases, if it is necessary to update or adjust the display of the target window in real time, the processed image data or related parameters in the memory device context environment can be passed back to the target window device environment in a specific way to achieve the optimization or update of the window display. Collaborative work ensures screenshot accuracy and efficiency: The memory device context and the target window device context work together to ensure the accuracy and efficiency of the screenshot operation. The target window device context provides the original image data source and basic display-related information, while the memory device context uses this information to perform efficient processing and optimization in memory. The two work together to ensure that the screenshot accurately reflects the actual display content of the target window and can complete the screenshot operation at a faster speed, improving the performance of the entire software automated testing screenshot system. For example, after obtaining the device context of the target window, the memory device context creates a suitable working environment based on its information, and then obtains image data from the target window device context for processing. During the processing, parameters such as image format and resolution in memory may be adjusted according to the display attributes of the target window. Finally, the processed screenshot result is accurately saved or used for subsequent analysis. The two work closely together and are indispensable in the entire process.

[0028] Furthermore, in this embodiment, the step of pre-allocating memory space for the memory device context includes: determining the remaining system memory based on the obtained total system memory capacity and current system memory usage, and determining the resolution and color depth of the screenshot based on the size of the target window and the intended use of the screenshot; calculating the amount of memory required for the screenshot using a preset memory allocation algorithm based on the remaining system memory, the resolution, and the color depth, and pre-allocating memory space for the memory device context based on the amount of memory required for the screenshot. By determining the current system memory resource status and the memory required for the screenshot, memory space is dynamically pre-allocated for the memory device context, optimizing memory management, ensuring that appropriate memory resources are allocated for the screenshot operation, avoiding screenshot failure due to insufficient memory allocation or resource waste due to excessive memory allocation, and better balancing the resource requirements of the screenshot task with other running programs through reasonable memory allocation, improving the overall performance and stability of the system. The specific implementation process of calculating and allocating the memory required for the memory device context is as follows: 1. Obtain system information Obtaining available system memory: The total system memory capacity and the amount of memory currently used can be obtained through system-provided interfaces or functions. In Windows, the 'GlobalMemoryStatusEx' function can be used to obtain detailed system memory information. This function populates a 'MEMORYSTATUSEX' structure, which contains information such as the total system physical memory ('ullTotalPhys' field) and the currently used physical memory ('ullAvailPhys' field). By calculating the difference between the two, the available system memory can be obtained. For example, assuming the total system memory is 8GB (8589934592 bytes) and the used memory is 4GB (4294967296 bytes), then the available system memory is 4GB (4294967296 bytes). This step provides the basic data for subsequent calculations of the maximum memory that can be allocated to the screenshot task. To obtain the memory usage of other programs: To more accurately determine the memory resources available for the screenshot task, it is necessary to obtain the memory usage of other currently running programs. This can be done by traversing the system process list to obtain the memory usage information of each process. In Windows systems, the 'ToolHelp32' series of functions (such as 'CreateToolHelp32Snapshot', 'Process32First', and 'Process32Next') can be used to obtain information about the processes running in the system, including process ID and process name. For each process, its memory usage can be further obtained. The method for obtaining process memory usage is through the 'GetProcessMemoryInfo' function, which can obtain information such as the working set size of a specified process. The memory usage of all running processes is added together to obtain the total amount of memory used by other programs in the current system. For example, after traversing, it is found that there are three running programs, using 500MB, 300MB, and 200MB of memory respectively. Then, the total memory usage of other programs is 1GB (1024MB). 2. Screenshot Task Requirements Assessment Impact of Estimated Screenshot Resolution: Based on the size of the target window and the intended use of the screenshot, the estimated screenshot resolution is determined. If it's for a test report and requires detailed display of the window content, a higher resolution, such as the same as the target window, may be used. If it's only for quick browsing or displaying basic test results, the resolution may be appropriately reduced. The resolution directly affects the required memory size because a higher resolution means storing more pixel information. For example, for a window with a resolution of 1920×1080, if a full-resolution screenshot is used, each pixel needs to occupy a certain amount of memory space (depending on the color depth; for example, with 32-bit color depth, each pixel occupies 4 bytes). Therefore, the image data alone would require 1920×1080×4 bytes of memory space. If the resolution is reduced to 960×540, the required memory space will be reduced accordingly. Consider color depth: Determine the color depth of the screenshot. Different color depths have a significant impact on memory usage. Common color depths include 8-bit (1 byte / pixel, representing 256 colors), 16-bit (2 bytes / pixel, representing 65,536 colors), and 32-bit (4 bytes / pixel, representing approximately 4.2 billion colors). For game graphics with rich colors or scenarios requiring high color accuracy, a 32-bit color depth may be necessary. However, for interfaces with a lot of text or simple colors, 8-bit or 16-bit color depth may be sufficient and can greatly reduce memory usage. For example, at the same 1920×1080 resolution, if a 32-bit color depth is used, the image data memory usage is 1920×1080×4 bytes; if an 8-bit color depth is used, the memory usage is 1920×1080×1 byte, a difference of four times. 3. Memory size calculation and allocation Calculate the total memory required: Based on the available system memory, memory usage of other programs, and the estimated resolution and color depth of the screenshot task, calculate the total memory required for the screenshot task. The formula is roughly as follows: Total memory required = Screenshot image data memory usage (calculated based on resolution and color depth) + Certain additional memory overhead (for memory management, data structures, etc.). The additional memory overhead can be determined based on experience or system performance test results. For example, reserving 10% - 20% additional memory space, assuming the available system memory is 4GB, other programs use 1GB, the estimated screenshot resolution is 1920×1080, using 32-bit color depth, the image data memory usage is 1920×1080×4 bytes (approximately 8MB), and reserving 20% ​​additional memory overhead, the total memory required is approximately 8MB×1.2 = 9.6MB (this is only an example calculation; actual calculations may involve more precise byte alignment and system memory management units, etc.). Memory Allocation and Adjustment: Based on the calculated total memory required, attempt to allocate corresponding memory space from the system to the memory device context. If the calculated memory requirement exceeds the system's actual allocatable memory limit (considering factors such as system reserved memory and the minimum memory requirements for other programs), adjustments are needed. Memory requirements can be reduced by lowering the screenshot resolution, adjusting color depth, or using a more efficient memory compression algorithm until memory can be successfully allocated under the current system resource conditions. For example, if 2GB of memory is calculated, but the system can only allocate a maximum of 1.5GB, the screenshot resolution might be lowered to 1280×720, and the memory requirement recalculated using 16-bit color depth until the system's allocatable memory limit is met. This ensures that sufficient but not excessive memory resources are allocated to the screenshot task without affecting overall system performance, allowing the screenshot operation to proceed smoothly.

[0029] Furthermore, in this embodiment, configuring the memory device context parameters includes: determining a suitable color mode and pixel format based on the type of the target window (e.g., game window, ordinary application window, etc.) and the intended use of the screenshot (test report, real-time analysis, etc.). For application scenarios with rich colors, a higher color depth (e.g., 32-bit true color) and a precise pixel format (e.g., 'ARGB' format) are selected. For windows mainly containing text and simple graphics, a more efficient compression format (e.g., 8-bit indexed color format) is selected to reduce memory usage and data transfer volume. The pixel format of the memory device context is set by calling the corresponding system function (e.g., the 'SetPixelFormat' function), and the 'ChoosePixelFormat' function is used to select the available pixel format closest to the desired format. Simultaneously, based on the selected color mode and pixel format, the relevant color table and palette information are configured to ensure the correct representation and processing of the image in memory. The criteria for determining the target window type include: 1. Window class name or title recognition The program can initially determine the type of a window by obtaining its class name or title. Different types of applications typically use specific window class names or set characteristic titles. For example, a game window might have a specific game name or game-related keywords as its title, or its window class name might be related to the game development framework. Through a predefined mapping table of window class names and titles, the program can identify whether a window belongs to a game window, a regular application window, or another specific type of window based on the obtained window class name or title. For example, game windows created by common game development engines (such as Unity, Unreal Engine, etc.) might have specific class name prefixes or contain specific keywords. By detecting whether these characteristic identifiers exist in the window class name, it can be determined whether the window is a game window. For regular applications, such as office software (Microsoft Word, Excel, etc.), their window class names and titles also have certain regularities, which can be used to distinguish them. 2. Window Properties and Function Detection In addition to class name and title, window attributes and functions can be further probed to determine its type. For example, game windows typically have high frame rates, support real-time graphics rendering and complex animation effects, and may have special response methods to input devices (such as mice and keyboards). By detecting attributes such as window refresh rate, graphics rendering characteristics, and input event handling methods, it is possible to help determine whether a window is a game window. For ordinary application windows, they may focus more on functions such as text editing and data display. The layout of elements and interaction methods in the window are relatively conventional. For example, text editing windows have a large number of text input boxes and editing menus, while image editing software windows may have rich drawing tools and image preview areas. By probing and analyzing these window attributes and functions, the type of the target window can be determined more accurately.

[0030] Methods for determining the intended use of screenshots include: 1. User settings or configuration file specifications When taking a screenshot, users can explicitly specify the intended use of the screenshot through the software's settings interface. For example, the software can provide a drop-down menu or option box, allowing users to choose whether the screenshot is for test reports, real-time analysis, illustrations in document editing, or other specific purposes. These user settings are recorded in a configuration file. When the program performs a screenshot operation, it can read the relevant information in the configuration file to know the intended use of the screenshot. Alternatively, users can also pass in an identifier for the purpose of the screenshot through command-line parameters or other means when starting a screenshot task. The program parses these parameters to determine the intended use of the screenshot. For example, if a user enters "screenshot -purposereport" in the command line, it indicates that this screenshot is for generating a test report, and the program determines the purpose of the screenshot based on the parsed "report" keyword. 2. Screenshot operation context judgment In some cases, the context of a screenshot operation can also hint at its intended use. For example, if a screenshot operation is triggered at a specific stage in a software automation testing process, such as automatically taking a screenshot after a test case is executed, it can be inferred that the screenshot is most likely used to generate a test report to record test results and interface status. If the screenshot operation is invoked in a real-time monitoring or performance analysis tool, the screenshot is likely used for real-time analysis to help developers or testers observe interface changes and performance during software runtime. In addition, the program can also infer the intended use of the screenshot based on currently open related documents or ongoing tasks. For example, if a technical document is being edited and the screenshot operation is triggered during document editing, the screenshot may be used to insert an illustration into the document as a description or example. By comprehensively considering the contextual information of these screenshot operations, the program can determine the intended use of the screenshot in order to configure appropriate memory device context parameters for it.

[0031] S2. Obtain device monitor information based on the device environment handle, determine the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot, create a bitmap object based on the size and resolution of the bitmap, configure parameters for the bitmap object, and store the bitmap object in the memory device context.

[0032] In this embodiment, the system utilizes a device monitor information acquisition interface (such as the 'GetDeviceCaps' function), passing in a window device context handle to obtain detailed monitor information such as the display's physical size (in pixels or millimeters), refresh rate (Hz), and pixel density (DPI). This information is stored in a predefined structure variable for subsequent calculations and use. By accurately acquiring and utilizing the device monitor information, the size and resolution of the bitmap are determined, enabling the screenshot to better reproduce the various details and features of the original image, improving the image quality of the screenshot, and providing more accurate data support for test analysis. If errors occur during the acquisition of device monitor information, such as unsupported device types or system configuration problems, the program should be able to handle these error situations, attempting to use default values ​​or providing reasonable alternatives to ensure that the program can continue to execute without crashing.

[0033] Furthermore, in this embodiment, determining the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot includes: when the intelligent computing model receives the device monitor information and the intended use information of the screenshot, determining the size of the bitmap based on the physical size and pixel density in the device monitor information, determining the resolution of the bitmap based on the refresh rate in the device monitor information, and adjusting the size and resolution of the bitmap based on the intended use information of the screenshot. While ensuring clarity, the resolution is appropriately reduced to decrease storage space and data processing volume, so that the screenshot meets various needs while optimizing system resource utilization and operational efficiency. Specifically, this includes: Based on the acquired device monitor information and the intended use of the screenshots, an intelligent computing model is used to determine the size and resolution of the bitmap. For screenshots requiring high-resolution details (such as those for interface design review or high-definition test reports), a suitable larger resolution bitmap space is calculated based on the monitor's physical size and pixel density. For quick browsing and basic test result display, while ensuring clarity, the resolution is appropriately reduced based on the monitor's refresh rate and expected display area size to minimize storage space and data processing. The 'CreateBitmap' or 'CreateCompatibleBitmap' function is called to create a bitmap object and select it into the previously created memory device context. When creating the bitmap, the correct parameters are set according to the calculated size and resolution to ensure that the bitmap can accurately accommodate the screenshot content. At the same time, sufficient memory space is allocated for the bitmap to store the image data. This process involves fine-grained management of system memory to avoid memory leaks and fragmentation issues. The intelligent computing model structure is as follows: 1. Data Input Layer This layer is responsible for receiving device monitor information and data related to the intended use of the screenshot. Device monitor information includes the physical size of the display (in pixels or millimeters), refresh rate (Hz), pixel density (DPI), etc. The intended use of the screenshot can be determined by the user or by the program based on context, such as identifiers for different purposes like test reports, real-time analysis, and archiving. This data serves as input to the model, providing a basis for subsequent calculations. For example, the physical size of the display (e.g., width 1920 pixels, height 1080 pixels), refresh rate (60Hz), pixel density (96 DPI), and the screenshot purpose identifier ("test report") are input into the model. 2. Computational Logic Layer This layer contains a series of calculation rules and algorithms that process the input data. For device monitor information, the calculation logic performs different calculations based on different parameter combinations. For example, it calculates the actual display area size (in pixels) based on the physical size and pixel density, and then considers whether a higher frame rate is needed for screenshots (a higher frame rate may be needed for real-time analysis, while a higher frame rate may not be needed for archiving). Depending on the intended use of the screenshot, the calculation logic adjusts the bitmap size and resolution according to predefined strategies. For example, if it's for test reports and requires detailed display of interface details, it may tend to maintain a higher resolution; if it's for quick browsing or real-time analysis and requires more detailed display of interface details, it may adjust the bitmap size and resolution according to predefined strategies. For applications requiring high real-time performance, the resolution may be appropriately reduced to improve processing speed while maintaining a certain level of clarity. Specific algorithms may involve operations such as proportional calculations and adjusting resolution based on usage weights. For example, based on the display area size calculated from the physical size and pixel density of the monitor, the calculation logic may set the resolution to be close to or equal to the display area size for screenshots used in test reports to obtain the clearest image. However, for applications used in real-time analysis with high refresh rates (such as 120Hz), the resolution may be reduced to a certain percentage (such as 70%) of the original calculated value. At the same time, the bitmap storage format and data processing method may be adjusted according to the frame rate requirements to balance image quality and processing speed. 3. Output layer Based on the processing results of the computational logic layer, the output layer determines the final bitmap size and resolution values. These values ​​will serve as parameters for creating bitmap objects, ensuring that the bitmap accurately adapts to the characteristics of the device monitor and the intended use of the screenshot. The output format may be a specific structure or data format, containing the bitmap's width (in pixels), height (in pixels), and resolution-related parameters (such as pixels per inch). For example, the output result may be a structure containing a bitmap width of 1920 pixels, a height of 1080 pixels, and a resolution of 96 DPI, which is used to set its properties when creating subsequent bitmap objects.

[0034] The process of determining the bitmap size and resolution is as follows: 1. Preliminary calculations based on equipment monitor information Based on the monitor's physical dimensions (pixel width and height) and pixel density, a basic bitmap size that can theoretically fully display the window content is calculated. For example, if the monitor's physical width is 1920 mm and the pixel density is 96 DPI, by conversion (1 inch = 25.4 mm), the number of pixels per inch in the horizontal direction is 96. Then the horizontal pixel width is 1920 / (25.4 / 96) ≈ 7168 pixels (this is an example calculation; actual calculations may involve more precise conversions and rounding rules). Similarly, the vertical pixel height is calculated to obtain a basic bitmap size. Regarding refresh rate, if it is used for real-time analysis or needs to capture dynamic changes, a suitable frame rate-related parameter will be determined based on the refresh rate. This parameter may affect the bitmap storage format or the processing method when taking continuous screenshots to ensure that the screen changes at different times can be accurately captured and to a certain extent balance the data volume and real-time requirements. For example, if the refresh rate is 120Hz, a suitable time interval may be set to acquire images of different frames when taking continuous screenshots, while adjusting the bitmap storage format to adapt to fast data writing and reading. 2. Adjustments based on the intended use of the screenshot. If the screenshot is intended for use in a test report and requires detailed display of interface details, the base bitmap size and resolution calculated above may be used directly to ensure that the screenshot clearly and accurately reflects all information of the window, providing high-quality image data for test analysis. If it is used for fast browsing or real-time analysis with high real-time requirements, the resolution will be appropriately reduced according to a predefined strategy while ensuring clarity. For example, the base resolution may be reduced by a certain percentage (such as the 70% mentioned above), while optimizing the bitmap compression format to reduce data volume and improve data transmission and processing speed. If it is used for archiving and storage space is limited, a more efficient compression algorithm and appropriate resolution adjustment may be used to minimize file size and save storage space while ensuring that the image is basically recognizable and key information is complete.

[0035] In this way, by combining information from the device monitor and the intended use of the screenshot, the intelligent computing model can determine the most suitable bitmap size and resolution, so that the screenshot can meet various needs while optimizing system resource utilization and operational efficiency.

[0036] S3. Copy the image data corresponding to the device environment handle to the bitmap object, process the image data in the bitmap object, export and save the processed image data from the bitmap object, and clean up and release system resources.

[0037] In this embodiment, the 'BitBlt' function (or a similar graphics copy function) is used to copy image data from the window device context to a bitmap object in the memory device context. This function achieves efficient image data transfer by specifying parameters such as the source device context, the target device context, and the copy area (usually the entire window or a specified rectangular area). It copies the image data corresponding to the device context handle to the bitmap object. During the image data copying process, efficiency is improved by optimizing the data transmission channel and caching mechanism. For example, setting an appropriate cache size and data block transfer method reduces the number of data transfers between memory and the system bus, thereby speeding up the process. The system improves screenshot speed and performs error detection and handling during the copying process to ensure that image data is copied completely and accurately to the bitmap. If some data is lost or incorrect, it attempts to copy again or performs data recovery operations. The image data in the bitmap object is processed to improve image clarity and smoothness, optimize the visual effect of the image, and make the image clearer and more beautiful, which is convenient for subsequent test analysis and report generation. The processed image data is exported from the bitmap object and saved, and system resources are cleaned up and released to avoid resource leakage that could lead to system performance degradation or other program operation problems, so that the next screenshot operation can be performed normally, ensuring the stability and reliability of the test process.

[0038] Furthermore, in this embodiment, processing the image data in the bitmap object and exporting and saving the processed image data from the bitmap object includes: creating an image data copy, detecting noise points in the image data copy using an image analysis algorithm, removing noise using a filtering algorithm, adjusting the brightness and contrast distribution of the image data copy according to a preset target value, and updating the adjusted image data copy to the image data of the bitmap object. The filtering algorithm includes median filtering and Gaussian filtering. The implementation method for updating the adjusted image data copy to the image data of the bitmap object includes: 1. Memory data replacement After processing and passing quality checks, the program copies the processed image data pixel by pixel back to the memory space occupied by the bitmap object, overwriting the original image data. This process involves precise manipulation of the data in memory to ensure that the color value, position, and other information of each pixel are correctly updated. For example, a loop is used to traverse the processed image data array and the memory data area of ​​the bitmap object, writing each pixel value in the processed image data sequentially into the memory space of the bitmap object according to the pixel format of the bitmap object (such as RGB or ARGB), thus updating the image data. During this process, the memory layout and data storage format requirements of the bitmap object must be strictly followed to ensure data integrity and correctness. 2. Notify the bitmap object of an update. In addition to directly copying the data, it is also necessary to notify the bitmap object that the data has been updated. The bitmap object may have some internal states or properties used to record information such as the validity of the image data. After the data is updated, by calling the corresponding method of the bitmap object or setting a specific flag, the bitmap object is informed that its stored image data has changed and that the new data needs to be used in subsequent operations (such as saving the image, displaying a preview, etc.). For example, in some graphics libraries or frameworks, there may be functions like 'InvalidateBitmap'. Calling this function can make the bitmap object reload its internally stored image data, ensuring that the processed and updated image data is used in subsequent operations. In this way, when the image saving operation is performed, the bitmap object will export the updated image data according to the specified file format (such as PNG, JPEG, etc.) and save it to the file system, ensuring that the final saved image is a processed high-quality image.

[0039] By creating and processing a copy of the image data, irreversible damage to the original image data is avoided. The adjusted copy is then used to update the image data of the bitmap object, resulting in clearer and more aesthetically pleasing image data. This facilitates subsequent testing, analysis, and report generation, while maintaining data consistency and ensuring operational continuity. The reasons for this are as follows: 1. Maintain data consistency: Bitmap objects are the core objects used to store and manage screenshot image data. In the entire screenshot process, subsequent operations (such as saving the image) are based on the data in the bitmap object. If the processed image data is not updated to the bitmap object, the image that is finally saved or used will still be the unprocessed original image. This contradicts the purpose of image processing and cannot achieve the effect of improving image quality (such as removing noise, optimizing contrast and brightness). For example, after processing such as removing image noise and optimizing contrast, if the bitmap object is not updated, when the image is saved as a file, the result will be the original image containing noise and with unoptimized contrast, which cannot meet the user's demand for high-quality screenshots. 2. Ensure operational continuity From the perspective of the continuity of the screenshot process, image processing is a crucial step, and its results should be fed back into the entire process. Updating the bitmap object with the processed image data ensures that subsequent operations (such as saving the image or using the screenshot in the test report) can obtain the optimized image data, guaranteeing the integrity and correctness of the entire screenshot system's operational logic. For example, in software automation testing, if the processed image data is not updated to the bitmap object, the screenshot inserted when generating the test report will not be able to display the processed effect, affecting the accuracy and readability of the test report, and consequently impacting the effectiveness of the entire testing process.

[0040] The process of processing the image data in the bitmap object, and exporting and saving the processed image data from the bitmap object, includes: setting the saving parameters of the image data, using an image encoding library to convert the image data into file data in a preset format, and exporting and saving the file data according to a preset saving path. The preset format can be PNG, JPEG, etc., and the image encoding library can be 'libpng', 'libjpeg', etc. By setting the saving parameters of the image data, the relationship between file size and image quality is balanced to ensure image clarity. Simultaneously, error handling is performed on the file saving operation to ensure that the image can be correctly saved to the specified location. If saving fails, detailed error information should be provided to the user, and attempts may be made to save to other available locations or a backup saving option may be provided.

[0041] In this embodiment, after the image data copy processing operation is completed, a quality check is performed to ensure that the processed image meets the expected quality standards. If the processing result is not ideal, the processing parameters may be adjusted or other alternative processing algorithms may be used. The quality check includes: 1. Quality Inspection Contents Image sharpness assessment: Check if the edges of the image are sharp and whether there is blurring or jaggedness. Sharpness can be assessed by calculating the gradient of the edges of objects in the image. The larger the gradient value, the sharper the edges. For example, for a screenshot containing text and graphics, check if the strokes of the text are clearly distinguishable and if the outlines of the graphics are sharp. Analyze the richness of image details to ensure that no important details are lost during processing. For example, for game screenshots, check if the textures, effects, and other details in the game scene are completely preserved; for software interface screenshots, check if the details of elements such as buttons and icons are clearly presented. Color accuracy check: Compare the color values ​​of the processed image with those of the original image (or a known standard color reference) to ensure that there is no color deviation or distortion. Calculate the average and variance of the color values ​​for specific color regions in the image (such as icons of known colors, backgrounds of specific colors, etc.) to determine the accuracy of the colors. Check the color balance of the image to ensure that the overall colors look natural and harmonious. For example, avoid situations where some colors are too bright or too dark, causing an overall color imbalance in the image. For images containing multiple colors, analyze whether the proportional relationship between different color channels (such as RGB channels) is reasonable. Noise level detection: Evaluate the noise content in the image to ensure that the processing effectively removes noise or does not introduce new noise. Calculate the noise variance of the image or use specific noise detection algorithms, such as wavelet transform-based noise detection methods. Check the distribution of noise in the image to avoid local noise concentration problems, such as whether the noise level is within an acceptable range and uniformly distributed in the dark or bright areas of the image. 2. Inspection Method Quantitative evaluation based on image analysis algorithms: This method uses image analysis algorithms to calculate values ​​for various quality indicators, such as sharpness indicators (e.g., gradient mean, variance), color difference indicators (e.g., root mean square of color difference), and noise indicators (e.g., noise variance). By comparing these calculated values ​​with pre-set thresholds, it can be determined whether the image quality meets the requirements. For example, if the calculated value of the sharpness indicator is lower than the set sharpness threshold, it may indicate that the image is not sharp enough, and further adjustments to processing parameters or replacement of processing algorithms are needed. This quantitative evaluation method can provide objective quality judgment criteria, facilitating automated processing and decision-making. Visual comparison inspection (optional auxiliary method): In some cases, in addition to quantitative evaluation, quality inspection can also be carried out through visual comparison. The processed image and the original image or reference image are displayed on the screen simultaneously (using methods such as split screen or overlay display), and the differences between the two are observed by the human. The human judges whether the quality of the processed image meets the expectations. Although this method is relatively subjective, in some cases where the requirements for image quality are high and it is difficult to fully measure by a single numerical indicator (such as the display of artworks, certain special effects processing, etc.), visual comparison inspection can be used as a supplementary means to help find some subtle problems that may be overlooked by quantitative evaluation. However, in automated test screenshot systems, visual comparison inspection may not be used as the main quality inspection method, but rather as an auxiliary method to evaluate the effect of the processing algorithm during the development and debugging phase. 3. Expected quality standards Clarity Standards: Set clarity standards based on the intended use of the screenshot. For example, if it is used for test reports or detailed analysis, a high level of image clarity metrics (such as gradient mean) is required to ensure that interface elements and details are clearly displayed, text is legible, and graphic outlines are distinct. Specific clarity thresholds can be determined through testing and analysis of a large number of different types of images. For example, for general software interface screenshots, the gradient mean may need to be greater than a certain value (such as 50) to ensure that interface elements are clearly distinguishable; for high-definition game screenshots, even higher clarity metric values ​​may be required. Color accuracy standards: Set an acceptable range for color differences to ensure that the color of the processed image deviates from the original image or the expected color within a certain limit. For example, the root mean square (RMSE) of the color difference should not exceed a certain value in a certain color space (such as RGB space). For ordinary images, an RMSE value of less than 10 (the specific value is determined according to the actual application and the requirements for color accuracy) indicates that the color accuracy is within an acceptable range. At the same time, there are also certain requirements for color balance, such as the relatively stable proportion of each color channel to avoid obvious color cast. Noise Standards: The upper limit of the noise level is determined based on the application scenario of the screenshot. For example, for general software screenshots, the noise variance should be lower than a certain set value (e.g., 0.1) to ensure a clean and clear image. For scenarios more sensitive to noise (such as preview screenshots in image processing software), an even lower noise level may be required, with a noise variance less than 0.05. Simultaneously, the noise distribution in the image should be relatively uniform to avoid excessively high local noise affecting image quality. These quality standards can be adjusted and optimized based on actual needs and user feedback to ensure that the processed screenshots achieve a high quality level and meet the requirements of different application scenarios.

[0042] Furthermore, in this embodiment, after the screenshot and image saving operations are completed, all allocated system resources are released sequentially, including memory device context handles, bitmap object handles, window device context handles, etc. These resources are released by calling the corresponding system functions (such as `DeleteDC`, `DeleteObject`, etc.) to avoid resource leaks that could lead to system performance degradation or other program operation problems. Temporary data structures, caches, and global variables used in the program are cleaned up and reset, restoring the system state to its initial state so that the next screenshot operation can be performed normally. At the same time, relevant information about this screenshot operation, such as screenshot time, image size, and save path, is recorded for subsequent statistical analysis and log recording, so as to track and evaluate the performance and effect of the screenshot operation.

[0043] Please refer to Figure 2 Embodiment 2 of the present invention is: a software automated test screenshot terminal 1, including a memory 2, a processor 3, and a computer program stored on the memory 2 and executable on the processor 3. When the processor 3 executes the computer program, it implements the various steps of the software automated test screenshot method of Embodiment 1.

[0044] In summary, the software automation testing screenshot method and terminal provided by this invention, in response to a screenshot operation, obtains the target window handle and its corresponding device context handle, including: calling a window enumeration function and traversing and searching all windows according to a preset window title or class name matching algorithm; if an error occurs during the window search process, recording the error information and re-traversing and searching or providing an error message, until the target window is found; obtaining the target window handle corresponding to the target window, and calling the device context acquisition function according to the target window handle to obtain the corresponding device context handle; checking the obtained device context handle; if the check result indicates that the acquisition of the device context has failed, releasing the obtained device context handle. The system reacquires the device context handle and uses a window enumeration function to search all windows based on a preset window title or class name matching algorithm to accurately locate the target window. This avoids inaccurate or failed screenshots due to window recognition errors and provides an error handling mechanism to improve program stability. The system checks the device context handle to ensure its validity and avoids rendering problems caused by invalid handles. A memory device context is created based on the device context handle, and memory space is pre-allocated for it. This includes determining the remaining system memory based on the total system memory capacity and current system memory usage, and then determining the remaining memory based on the size of the target window and the screenshot parameters. The system determines the resolution and color depth of the screenshot based on the intended use information. It calculates the required memory for the screenshot using a preset memory allocation algorithm based on the remaining system memory, the resolution, and the color depth. It then pre-allocates memory space for the memory device context based on this required memory space. This dynamic pre-allocation of memory space optimizes memory management by determining the current system memory resource status and the required memory for the screenshot, ensuring appropriate memory resources are allocated for the screenshot operation and avoiding screenshot failures due to insufficient memory allocation or resource waste due to excessive memory allocation. Finally, it obtains device monitor information based on the device environment handle and the intended use information of the screenshot. The method uses an intelligent computing model to determine the size and resolution of a bitmap, including: when the intelligent computing model receives the device monitor information and the intended use information of the screenshot, determining the size of the bitmap based on the physical size and pixel density in the device monitor information, determining the resolution of the bitmap based on the refresh rate in the device monitor information, adjusting the size and resolution of the bitmap based on the intended use information of the screenshot, creating a bitmap object based on the size and resolution of the bitmap and configuring parameters for the bitmap object, and storing the bitmap object in the memory device context environment, so that the screenshot can better restore various details and features of the original image, improve the image quality of the screenshot, and provide more accurate data support for test analysis;The image data corresponding to the device environment handle is copied to the bitmap object, and the image data in the bitmap object is processed. The processed image data is then exported from the bitmap object and saved. This process includes: creating an image data copy; detecting noise points in the image data copy using an image analysis algorithm and removing noise using a filtering algorithm; adjusting the brightness and contrast distribution of the image data copy according to a preset target value; and updating the image data of the bitmap object with the adjusted image data copy. The process also involves setting the image data saving parameters, converting the image data into a file data of a preset format using an image encoding library, exporting and saving the file data according to a preset save path. By creating and processing the image data copy, irreversible damage to the original image data is avoided. The adjusted image data copy is then updated to the image data of the bitmap object, making the image data of the bitmap object clearer and more aesthetically pleasing, facilitating subsequent test analysis and report generation. Setting the image data saving parameters balances file size and image quality, ensuring image clarity. System resources are also cleaned up and released to prevent resource leaks that could lead to system performance degradation or other program operation problems, ensuring that subsequent screenshot operations can proceed normally and guaranteeing the stability and reliability of the testing process. ;

[0045] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A method for taking screenshots during automated software testing, characterized in that, Including the following steps: S1. In response to the screenshot operation, obtain the target window handle and its corresponding device context handle, create a memory device context based on the device context handle, and pre-allocate memory space for the memory device context. S2. Obtain device monitor information based on the device environment handle; determine the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot; create a bitmap object based on the size and resolution of the bitmap and configure parameters for the bitmap object; and store the bitmap object in the memory device context. S3. Copy the image data corresponding to the device environment handle to the bitmap object, process the image data in the bitmap object, export and save the processed image data from the bitmap object, and clean up and release system resources.

2. The software automated testing screenshot method according to claim 1, characterized in that, The step of obtaining the target window handle and its corresponding device context handle includes: Call the window enumeration function and traverse all windows according to the preset window title or class name matching algorithm. If an error occurs during the window search process, record the error information and traverse the search again or provide an error message until the target window is found. Obtain the target window handle corresponding to the target window, and call the device context function to obtain the corresponding device environment handle based on the target window handle. Check the obtained device environment handle. If the check result indicates that the acquisition of device environment has failed, release the obtained device environment handle and reacquire the device environment handle.

3. The software automated testing screenshot method according to claim 1, characterized in that, The step of pre-allocating memory space for the memory device context includes: Based on the obtained total system memory capacity and current system memory usage, the remaining system memory is determined, and the resolution and color depth of the screenshot are determined based on the size of the target window and the intended use of the screenshot. The amount of memory required for taking a screenshot is calculated using a preset memory allocation algorithm based on the remaining system memory, the resolution, and the color depth, and memory space is pre-allocated to the memory device context environment based on the amount of memory required for the screenshot.

4. The software automated testing screenshot method according to claim 1, characterized in that, The step of determining the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot includes: When the intelligent computing model receives the device monitor information and the intended use information of the screenshot, it determines the size of the bitmap based on the physical size and pixel density in the device monitor information, determines the resolution of the bitmap based on the refresh rate in the device monitor information, and adjusts the size and resolution of the bitmap based on the intended use information of the screenshot.

5. The software automated testing screenshot method according to claim 1, characterized in that, The step of processing the image data in the bitmap object, and exporting and saving the processed image data from the bitmap object, includes: Create an image data copy, detect noise points in the image data copy using an image analysis algorithm, remove noise using a filtering algorithm, adjust the brightness and contrast distribution of the image data copy according to a preset target value, and update the image data of the bitmap object with the adjusted image data copy; Set the image data saving parameters, use an image encoding library to convert the image data into file data in a preset format, and export and save the file data according to the preset save path.

6. A software automated testing screenshot terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it performs the following steps: S1. In response to the screenshot operation, obtain the target window handle and its corresponding device context handle, create a memory device context based on the device context handle, and pre-allocate memory space for the memory device context. S2. Obtain device monitor information based on the device environment handle; determine the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot; create a bitmap object based on the size and resolution of the bitmap and configure parameters for the bitmap object; and store the bitmap object in the memory device context. S3. Copy the image data corresponding to the device environment handle to the bitmap object, process the image data in the bitmap object, export and save the processed image data from the bitmap object, and clean up and release system resources.

7. A software automated testing screenshot terminal according to claim 6, characterized in that, The step of obtaining the target window handle and its corresponding device context handle includes: Call the window enumeration function and traverse all windows according to the preset window title or class name matching algorithm. If an error occurs during the window search process, record the error information and traverse the search again or provide an error message until the target window is found. Obtain the target window handle corresponding to the target window, and call the device context function to obtain the corresponding device environment handle based on the target window handle. Check the obtained device environment handle. If the check result indicates that the acquisition of device environment has failed, release the obtained device environment handle and reacquire the device environment handle.

8. A software automated testing screenshot terminal according to claim 6, characterized in that, The step of pre-allocating memory space for the memory device context includes: Based on the obtained total system memory capacity and current system memory usage, the remaining system memory is determined, and the resolution and color depth of the screenshot are determined based on the size of the target window and the intended use of the screenshot. The amount of memory required for taking a screenshot is calculated using a preset memory allocation algorithm based on the remaining system memory, the resolution, and the color depth, and memory space is pre-allocated to the memory device context environment based on the amount of memory required for the screenshot.

9. A software automated testing screenshot terminal according to claim 6, characterized in that, The step of determining the size and resolution of the bitmap using an intelligent computing model based on the device monitor information and the intended use information of the screenshot includes: When the intelligent computing model receives the device monitor information and the intended use information of the screenshot, it determines the size of the bitmap based on the physical size and pixel density in the device monitor information, determines the resolution of the bitmap based on the refresh rate in the device monitor information, and adjusts the size and resolution of the bitmap based on the intended use information of the screenshot.

10. A software automated testing screenshot terminal according to claim 6, characterized in that, The step of processing the image data in the bitmap object, and exporting and saving the processed image data from the bitmap object, includes: Create an image data copy, detect noise points in the image data copy using an image analysis algorithm, remove noise using a filtering algorithm, adjust the brightness and contrast distribution of the image data copy according to a preset target value, and update the image data of the bitmap object with the adjusted image data copy; Set the image data saving parameters, use an image encoding library to convert the image data into file data in a preset format, and export and save the file data according to the preset save path.