A picture processing method, device and storage medium
By enumerating small images by width and generating an aggregated image, the problems of long program initialization time and large memory consumption are solved, achieving fast startup and compact image arrangement, reducing memory fragmentation and space waste.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU SHUNWANG TECH
- Filing Date
- 2023-08-03
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies suffer from long program initialization times and high memory consumption when processing a large number of small image files, and cannot effectively reduce memory fragmentation and space waste.
All images are enumerated in descending order of width to generate an aggregated image. By selecting the position of the images and saving the rectangle position, they are merged into a single aggregated image. The program only reads the aggregated image file during runtime, reducing memory usage and fragmentation.
It improves program startup speed, reduces memory usage and fragmentation, saves space, adapts to various image sizes, and minimizes the area of aggregated images.
Smart Images

Figure CN116883487B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image processing method, apparatus, and storage medium. Background Technology
[0002] Computer programs typically use numerous small images when implementing a user interface (UI), such as button images, scroll bar images, and program logo images. These small images vary in size, including near-square, long horizontal bars, and long vertical bars, and each small image corresponds to a separate file. During program execution, these small image files are read from the disk, their file formats are parsed, and they are loaded into memory. When the number of small image files is too large, it increases program initialization time, consumes more memory, and impacts performance.
[0003] Currently, to speed up program startup, numerous small image files are packaged into a single compressed file or a composite file. Upon program startup, the small image files are decompressed to disk or memory, and then loaded and parsed one by one. While this approach solves the problem of needing to read numerous files from disk, it still ultimately loads and parses small image files one by one, failing to reduce memory fragmentation and overall memory usage. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide an image processing method, device, and storage medium that can improve program startup speed, reduce program memory fragmentation and memory usage, and minimize the area of the aggregated image, thus reducing space waste. The specific solution is as follows:
[0005] An image processing method, comprising:
[0006] Enumerate all images in descending order of width;
[0007] When no image has been inserted in the current row of the aggregate image to be generated, based on the width and height of the unprocessed image and the set width of the aggregate image, select the tallest unprocessed image other than the currently enumerated image, or align the currently enumerated image with the top left corner of the current row, and save the corresponding rectangle position, marking it as processed;
[0008] When an image has been inserted in the current row of the aggregated graph, based on the width and height of the current enumerated image and the width and height of the first image inserted in the current row, the current enumerated image is either aligned below the previous image already inserted in the current row or a recursive function is called to process the rectangular area on the right side of the current row where no image has been inserted, and the corresponding rectangular position is saved and marked as processed.
[0009] When the current enumerated image has been processed and the current enumerated image is the last image, the aggregated image is generated.
[0010] Read the file of the aggregated image and the saved rectangle positions, and draw the corresponding image.
[0011] Preferably, in the image processing method provided in the embodiments of the present invention, based on the width and height of the unprocessed image and the set width of the aggregated image, the tallest unprocessed image (excluding the currently enumerated image) or the currently enumerated image aligned with the top left corner of the current row is selected, and the corresponding rectangular position is saved and marked as processed, including:
[0012] Select the tallest image from the unprocessed images, excluding the currently enumerated images.
[0013] Determine whether the height of the selected highest image is greater than the height of the current enumerated image, and whether the sum of the widths of the selected and current enumerated images is less than or equal to the set width of the aggregated image;
[0014] If so, align the selected highest image with the top left corner of the current row, save the rectangular position of the selected highest image in the aggregate image, and mark it as processed;
[0015] If not, align the current enumerated image with the top left corner of the current row, save the rectangular position of the current enumerated image in the aggregated image, and mark it as processed.
[0016] Preferably, in the image processing method provided in the embodiments of the present invention, based on the width and height of the currently enumerated image and the width and height of the first image inserted in the current row, the method selects to align the currently enumerated image below the previous image already inserted in the current row or calls a recursive function to process the rectangular area on the right side of the current row where no image has been inserted, and saves the corresponding rectangular position, marking it as processed, including:
[0017] Determine whether the difference between the width of the currently enumerated image and the width of the first image inserted in the current row is within a set range, and whether the sum of the heights of the images and the heights of the first image inserted in the current row is less than or equal to the width of the first image inserted in the current row;
[0018] If so, align the current enumerated image below the previous image already inserted in the current row, save the rectangular position of the current enumerated image in the aggregated image, and mark it as processed;
[0019] If not, a recursive function is called to process the rectangular area to the right of the current row where no image has been inserted.
[0020] Preferably, in the image processing method provided in the embodiments of the present invention, the step of calling a recursive function to process the rectangular area on the right side of the current row where no image has been inserted includes:
[0021] Enumerate the unprocessed images in descending order of width;
[0022] Determine whether the rectangular area to the right of the current row, where no image has been inserted before, is large enough to accommodate the currently enumerated image;
[0023] If there is enough space, then selective processing is performed based on whether an image has been inserted in the current row within the rectangular area;
[0024] If the current enumerated image cannot be included, the recursive function processing flow ends when the current enumerated image is the last image; if the current enumerated image is not the last image, the next image is enumerated.
[0025] Preferably, in the image processing method provided in the embodiments of the present invention, selective processing based on whether an image has been inserted in the current row of the rectangular region includes:
[0026] If no image has been inserted in the current row of the rectangular area, then the tallest image other than the currently enumerated image is selected from the unprocessed images.
[0027] Determine whether the rectangular area can accommodate the selected tallest image, whether the height of the selected tallest image is greater than the height of the currently enumerated image, and whether the sum of the widths of the selected tallest image and the currently enumerated image is less than or equal to the width of the rectangular area.
[0028] If so, align the selected highest image with the top left corner of the current row, save the rectangular position of the selected highest image in the aggregate image, and mark it as processed;
[0029] If not, align the current enumerated image with the top left corner of the current row, save the rectangular position of the current enumerated image in the aggregated image, and mark it as processed.
[0030] Preferably, in the image processing method provided in the embodiments of the present invention, selective processing based on whether an image has been inserted in the current row of the rectangular region further includes:
[0031] When an image has been inserted in the current row of the rectangular area, it is determined whether the difference between the width of the currently enumerated image and the width of the first image inserted in the current row is within a set range, and whether the sum of the heights of the images is less than or equal to the width of the first image inserted in the current row.
[0032] If so, align the current enumerated image below the previous image already inserted in the current row, save the rectangular position of the current enumerated image in the aggregated image, and mark it as processed;
[0033] If not, the remaining blank area of the current row is divided into a bottom rectangular area and a right rectangular area, and a recursive function is called to process the bottom rectangular area and the right rectangular area respectively.
[0034] Preferably, in the image processing method provided in the embodiments of the present invention, when the current enumerated image has been processed and the current enumerated image is the last image, the aggregated image is generated, including:
[0035] Determine whether the currently enumerated image has been processed;
[0036] If it has been processed, then determine whether the currently enumerated image is the last image; if it has not been processed, then proceed to determine whether no image has been inserted in the current row.
[0037] If the currently enumerated image is the last image, then the aggregated image is generated; if the currently enumerated image is not the last image, then the next image is enumerated.
[0038] Preferably, in the image processing method provided in the embodiments of the present invention, before enumerating all images in descending order of width, the method further includes:
[0039] Initialize the width of the aggregated image to the width of the widest image;
[0040] Calculate the sum of the areas of all images and take the square root;
[0041] If the sum of the width of the tallest image (excluding the widest image) and the width of the widest image is less than or equal to one-third of the square root, then the width of the aggregated image is set to twice the width of the widest image.
[0042] If the sum of the width of the tallest image (excluding the widest image) and the width of the widest image is greater than one-third of the square root but less than or equal to the square root, then the width of the aggregated image is set to the sum of the width of the tallest image (excluding the widest image) and the width of the widest image.
[0043] This invention also provides an image processing device, including a processor and a memory, wherein the processor executes a computer program stored in the memory to implement the image processing method described above as provided in this invention.
[0044] This invention also provides a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the image processing method described above in this invention.
[0045] As can be seen from the above technical solution, the image processing method provided by the present invention includes: enumerating all images according to their width from largest to smallest; when no image has been inserted in the current row of the aggregated image to be generated, selecting the tallest image among the unprocessed images (excluding the currently enumerated image) or aligning the currently enumerated image with the upper left corner of the current row based on the width and height of the unprocessed image and the set width of the aggregated image, and saving the corresponding rectangular position and marking it as processed; when an image has been inserted in the current row of the aggregated image, selecting to align the currently enumerated image with the previous image inserted in the current row or calling a recursive function to process the rectangular area on the right side of the current row where no image has been inserted based on the width and height of the currently enumerated image and the width and height of the first image inserted in the current row, and saving the corresponding rectangular position and marking it as processed; when the currently enumerated image has been processed and is the last image, then the aggregated image is generated; reading the file of the aggregated image and the saved rectangular position, and drawing the corresponding image.
[0046] The image processing method provided by this invention merges all image files into a single aggregated image. Each image corresponds to a rectangular area within the aggregated image. During program execution, only the aggregated image file needs to be read, parsed, and loaded once. Only the header information of the aggregated image is stored in memory. When an image needs to be drawn, only the aggregated image file and the saved rectangular positions need to be read; it is not necessary to read the file data of all the images. This improves program startup speed, reduces memory fragmentation and memory usage, and can adapt to various image sizes, allowing for a more compact arrangement of images within the aggregated image, minimizing the area of the aggregated image, and reducing space waste.
[0047] Furthermore, the present invention also provides a corresponding device and computer-readable storage medium for the image processing method, further making the above method more practical, and the device and computer-readable storage medium have corresponding advantages. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0049] Figure 1 A flowchart of an image processing method provided in an embodiment of the present invention;
[0050] Figure 2 This is one of the schematic diagrams of the aggregation diagram provided in the embodiments of the present invention;
[0051] Figure 3This is a second schematic diagram of an aggregation diagram provided in an embodiment of the present invention;
[0052] Figure 4 A detailed flowchart of the image processing method provided in this embodiment of the invention;
[0053] Figure 5 The following is a flowchart illustrating the specific process of calling recursive functions in an embodiment of the present invention. Detailed Implementation
[0054] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0055] This invention provides an image processing method, such as... Figure 1 As shown, it includes the following steps:
[0056] S101. Enumerate all images in descending order of width.
[0057] It should be noted that the "images" described in this invention can be understood as small skin images used in the program. These small images vary in size, including near-square, long horizontal stripes, long vertical stripes, etc.
[0058] Step S101 enumerates all images in descending order of width, which means listing all images one by one in descending order of image width; the currently enumerated image is the widest image among the unprocessed images.
[0059] In a specific implementation, the image processing method provided in the embodiments of the present invention may further include the following steps before enumerating all images in descending order of width in step S101:
[0060] Load all small image files and sort them from largest to smallest image width;
[0061] Initialize the width of the aggregated image to the width of the widest image;
[0062] The sum of the areas of all images is the theoretical minimum area of the aggregated graph. The square root of this sum is sqrt_len, which represents the side length of the theoretical square aggregated graph.
[0063] If the sum of the width of the tallest image (excluding the widest image) and the width of the widest image (img_width_big) is less than or equal to one-third of the square root (sqrt_len), then the width of the aggregate image is set to twice the width of the widest image (img_width_big); this can prevent the generated aggregate image from being too narrow and long.
[0064] If the sum of the width of the tallest image (excluding the widest image) and the width of the widest image (img_width_big) is greater than one-third of the square root (sqrt_len) but less than or equal to the square root (sqrt_len), then the width of the aggregated image is set to the sum of the width of the tallest image (excluding the widest image) and the width of the widest image (img_width_big).
[0065] Afterwards, the state of all small images can be initialized to unprocessed; the height of the aggregate image can be set to infinity (initialization information, no real image is created).
[0066] S102. When no image has been inserted in the current row of the aggregate image to be generated, select the tallest image among the unprocessed images (excluding the currently enumerated image) or align the currently enumerated image with the top left corner of the current row, based on the width and height of the unprocessed image and the set width of the aggregate image, and save the corresponding rectangle position, marking it as processed.
[0067] In practical applications, the images can be arranged row by row, starting from the top left corner (coordinate 0, 0) of the aggregated image and proceeding from left to right and from top to bottom.
[0068] Step S102 involves the case where no image has been inserted in the current row. In this invention, based on the width and height values of the unprocessed image and the set width value of the aggregated image, it is selected whether to align the tallest unprocessed image (excluding the currently enumerated image) with the top left corner of the current row or to align the currently enumerated image with the top left corner of the current row. After selection, the rectangular position of the selected image needs to be saved and marked as processed.
[0069] It should be noted that the rectangular position refers to the rectangular area in the aggregated image that identifies the image name key, and can include the coordinates of the top-left, top-right, bottom-left, and bottom-right corners of the rectangular area. Each image corresponds to a rectangular area in the aggregated image.
[0070] S103. When an image has been inserted in the current row of the aggregate graph to be generated, based on the width and height of the current enumerated image and the width and height of the first image inserted in the current row, choose to align the current enumerated image below the previous image already inserted in the current row or call a recursive function to process the rectangular area on the right side of the current row where no image has been inserted, and save the corresponding rectangular position and mark it as processed.
[0071] Step S103 involves the case where an image has been inserted in the current row (i.e., an image has been inserted on the left side in step S102). In this invention, based on the width and height values of the currently enumerated image and the width and height values of the first image inserted in the current row, it is determined whether to align the currently enumerated image below the image that has been inserted in the current row, or to call a recursive function to process the rectangular area on the right side of the current row where no image has been inserted. After making the selection, the corresponding rectangular position needs to be saved and marked as processed.
[0072] It should be noted that existing image arrangement methods generally sort images from largest to smallest area and place them sequentially into the aggregate image, which leads to a large amount of wasted space. The actual area of the aggregate image will be much larger than the theoretical minimum area (i.e., the sum of the areas of all images). In order to avoid wasting space, this invention selectively inserts images according to their height and width through steps S102 and S103, and the area of the generated aggregate image will be close to the theoretical minimum area.
[0073] S104. When the current enumerated image has been processed and is the last image in the enumeration, an aggregated image is generated.
[0074] Steps S102 and S103 involve executing the LoopA loop. After LoopA completes, all images are arranged, and the height of the aggregated image is obtained. At this step, the width and height of the aggregated image are calculated, and the rectangular position of each small image within the aggregated image is determined. In practical applications, after calculating the width and height of the aggregated image, a transparent 32-bit ARGB aggregated image is obtained. Then, each small image is copied to a specified rectangular area of the aggregated image (the previously saved rectangular position) using a graphics library. Graphics libraries such as GDI, GDI+, and the open-source CxImage can be used. In this way, an aggregated image containing all the small images is generated. Figure 2 and Figure 3 Two examples of aggregation graphs are shown.
[0075] In specific implementation, such as Figure 4 As shown, in step S104, when the current enumerated image has been processed and is the last image, an aggregated image is generated. This can specifically include the following steps:
[0076] Determine whether the currently enumerated image has been processed;
[0077] If it has been processed, then determine whether the current enumerated image is the last image; if it has not been processed, then proceed to determine whether no image has been inserted in the current row.
[0078] If the current enumerated image is the last image, then generate an aggregated image; if the current enumerated image is not the last image, then continue enumerating the next image.
[0079] S105. Read the file of the aggregated graph and the saved rectangle positions, and draw the corresponding image.
[0080] It should be noted that this invention can save the rectangular position corresponding to each image to a JSON or other format file. When packaging the program, only this aggregated image and the position information file need to be included. When the program runs, it loads this aggregated image file and can draw the images based on the position information of each image in the aggregated image.
[0081] In the image processing method provided in this embodiment of the invention, all image files are merged into a single aggregated image. Each image corresponds to a rectangular area within the aggregated image. During program execution, only the aggregated image file needs to be read and parsed once. Only the header information of the aggregated image is stored in memory. When an image needs to be drawn, only the aggregated image file and the saved rectangular positions need to be read; it is not necessary to read the file data of all the images. This improves program startup speed, reduces memory fragmentation and memory usage, and can adapt to various image sizes, allowing for a more compact arrangement of images within the aggregated image, minimizing the area of the aggregated image, and reducing space waste.
[0082] Furthermore, in specific implementation, in the image processing method provided in the embodiments of the present invention, in step S102, when no image has been inserted in the current row of the aggregated image to be generated, based on the width and height of the unprocessed image and the set width of the aggregated image, the tallest unprocessed image (excluding the currently enumerated image) or the currently enumerated image is aligned with the upper left corner of the current row, and the corresponding rectangular position is saved and marked as processed, such as... Figure 4 As shown, the specific steps may include:
[0083] When no image has been inserted in the current row of the aggregate graph to be generated, select the tallest image H from the unprocessed images, excluding the currently enumerated image (the widest image among the unprocessed images);
[0084] Determine whether the height of the highest image H is greater than the height of the current enumerated image, and whether the sum of the width of the highest image H and the width of the current enumerated image is less than or equal to the set width of the aggregate image.
[0085] If so, align the highest image H to the top left corner of the current row, save the rectangular position of the highest image H in the aggregate graph, and mark it as processed;
[0086] If not, align the current enumerated image to the top left corner of the current row, save the rectangular position of the current enumerated image in the aggregate graph, and mark it as processed.
[0087] Furthermore, in specific implementation, in the image processing method provided in the embodiments of the present invention, in step S103, when an image has been inserted in the current row of the aggregate image to be generated, based on the width and height of the currently enumerated image and the width and height of the first image inserted in the current row, the method selects to align the currently enumerated image below the previous image already inserted in the current row or calls a recursive function to process the rectangular area on the right side of the current row where no image has been inserted, and saves the corresponding rectangular position, marking it as processed, such as... Figure 4 As shown, the specific steps may include:
[0088] When an image has been inserted into the current row of the aggregate image to be generated, it is determined whether the difference between the width of the current enumerated image and the width of the first image inserted in the current row is within a set range, and whether the sum of the heights of the current enumerated image and the height of the first image inserted in the current row is less than or equal to the width of the first image inserted in the current row; preferably, the value of the set range here can be very small, that is: determine whether the width of the current enumerated image is close to the width of the first image inserted in the current row.
[0089] If so, align the current enumerated image below the previous image already inserted in the current row, save the rectangular position of the current enumerated image in the aggregate graph, and mark it as processed; it should be noted that aligning below the previous image can be understood as still being in the current row, and multiple images can be arranged vertically in the current row. In addition, it can be imagined that the left side of the current row can be arranged into a near-square image area.
[0090] If not, the recursive function F is called to process the rectangular area to the right of the current row where no image has been inserted. Afterwards, the start of the next row can be marked from the bottom of the current row in the aggregate graph.
[0091] Next, return to loop A and continue enumerating images.
[0092] Furthermore, in a specific implementation, in the image processing method provided in the embodiments of the present invention, step S103 calls a recursive function to process the rectangular area on the right side of the current row where no image has been inserted, such as... Figure 5 As shown, the specific steps may include: enumerating unprocessed images in descending order of width; determining whether the rectangular area to the right of the current row, where no images have been inserted, can accommodate the currently enumerated image; if it can, selectively processing the images based on whether images have been inserted in the current row within the rectangular area; if it cannot (i.e., the width or height of the currently enumerated image), then ending the recursive function processing flow if the currently enumerated image is the last image; and continuing to enumerate the next image if the currently enumerated image is not the last image.
[0093] The above steps involve calling a recursive function to process the rectangular area to the right of the current row where no image has been inserted; this is the process of executing the LoopB loop. If the currently enumerated image has been processed, the loop returns to LoopB to continue enumerating the next image. If, after the LoopB loop completes, no image has been processed, it means that the rectangular area cannot accommodate any small images, or that all small images have been processed, and the recursive function exits.
[0094] Furthermore, in specific implementations, in the image processing method provided in the embodiments of the present invention, selective processing is performed based on whether an image has been inserted in the current row of the rectangular area, such as... Figure 5 As shown, the specific steps may include:
[0095] If no image has been inserted in the current row of the rectangular area, then select the highest image H from the unprocessed images, excluding the currently enumerated images;
[0096] Determine whether the rectangular area can accommodate the tallest image H, whether the height of the tallest image H is greater than the height of the currently enumerated image, and whether the sum of the width of the tallest image H and the width of the currently enumerated image is less than or equal to the width of the rectangular area.
[0097] If so, align the highest image H to the top left corner of the current row, save the rectangular position of the highest image H in the aggregate graph, and mark it as processed;
[0098] If not, align the current enumerated image to the top left corner of the current row, save the rectangular position of the current enumerated image in the aggregate graph, and mark it as processed. Return to LoopB to continue enumerating the next image.
[0099] Furthermore, in specific implementations, in the image processing method provided in the embodiments of the present invention, selective processing is performed based on whether an image has been inserted in the current row of the rectangular area, such as... Figure 5 As shown, it may also include the following steps:
[0100] When an image has been inserted in the current row of the rectangular area, it is determined whether the difference between the width of the currently enumerated image and the width of the first image inserted in the current row is within a set range, and whether the sum of the heights of the images is less than or equal to the width of the first image inserted in the current row. Preferably, the set range here can be very small, that is, it is determined whether the width of the currently enumerated image is close to the width of the first image inserted in the current row.
[0101] If so, align the current enumerated image below the previous image already inserted in the current row, save the rectangular position of the current enumerated image in the aggregate graph, and mark it as processed;
[0102] If not, the remaining blank area of the current row is divided into a bottom rectangular area and a right rectangular area, and the recursive function is called to process the bottom rectangular area and the right rectangular area respectively.
[0103] Understandably, the recursive function F places an image in the top left corner of the rectangular area to the right of the current row where no image has been inserted. Then, it divides the remaining blank area into a bottom rectangular area and a right rectangular area, and calls the function itself to process these two rectangles recursively.
[0104] The above steps can arrange a large number of images in a neat and compact manner, merge multiple small images into one large image, and make the size of the generated large image as small as possible, thereby improving the loading speed of the program and reducing memory usage.
[0105] Accordingly, this invention also discloses an image processing device, including a processor and a memory; wherein, when the processor executes a computer program stored in the memory, it implements the image processing method disclosed in the foregoing embodiments.
[0106] For more detailed information on the above methods, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0107] Furthermore, the present invention also discloses a computer-readable storage medium for storing a computer program; when the computer program is executed by a processor, it implements the aforementioned image processing method.
[0108] For more detailed information on the above methods, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0109] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the devices and storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.
[0110] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0111] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0112] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0113] The image processing method, device, and storage medium provided by the present invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. An image processing method, characterized in that, include: Enumerate all images in descending order of width; If no image has been inserted in the current row of the aggregated image to be generated, select the tallest image from the unprocessed images, excluding the currently enumerated image. Determine whether the height of the selected tallest image is greater than the height of the currently enumerated image, and whether the sum of its width and the width of the currently enumerated image is less than or equal to the set width of the aggregated image. If yes, align the selected tallest image to the top left corner of the current row, save the rectangular position of the selected tallest image in the aggregated image, and mark it as processed. If no, align the currently enumerated image to the top left corner of the current row, save the rectangular position of the currently enumerated image in the aggregated image, and mark it as processed. When an image has been inserted in the current row of the aggregated graph, based on the width and height of the current enumerated image and the width and height of the first image inserted in the current row, the current enumerated image is either aligned below the previous image already inserted in the current row or a recursive function is called to process the rectangular area on the right side of the current row where no image has been inserted, and the corresponding rectangular position is saved and marked as processed. When the current enumerated image has been processed and the current enumerated image is the last image, the aggregated image is generated. Read the file of the aggregated image and the saved rectangle positions, and draw the corresponding image.
2. The image processing method according to claim 1, characterized in that, Based on the width and height of the currently enumerated image and the width and height of the first image inserted in the current row, select either to align the currently enumerated image below the previously inserted image in the current row or to call a recursive function to process the rectangular area on the right side of the current row where no image has been inserted, and save the corresponding rectangular position, marking it as processed, including: Determine whether the difference between the width of the currently enumerated image and the width of the first image inserted in the current row is within a set range, and whether the sum of the heights of the images and the heights of the first image inserted in the current row is less than or equal to the width of the first image inserted in the current row; If so, align the current enumerated image below the previous image already inserted in the current row, save the rectangular position of the current enumerated image in the aggregated image, and mark it as processed; If not, a recursive function is called to process the rectangular area to the right of the current row where no image has been inserted.
3. The image processing method according to claim 2, characterized in that, The process of calling the recursive function to handle the rectangular area on the right side of the current row where no image has been inserted includes: Enumerate the unprocessed images in descending order of width; Determine whether the rectangular area to the right of the current row, where no image has been inserted before, is large enough to accommodate the currently enumerated image; If there is enough space, then selective processing is performed based on whether an image has been inserted in the current row within the rectangular area; If the current enumerated image cannot be included, the recursive function processing flow ends when the current enumerated image is the last image; if the current enumerated image is not the last image, the process continues to enumerate the next image.
4. The image processing method according to claim 3, characterized in that, Selective processing is performed based on whether an image has been inserted in the current row within the rectangular area, including: If no image has been inserted in the current row of the rectangular area, then the tallest image other than the currently enumerated image is selected from the unprocessed images. Determine whether the rectangular area can accommodate the selected tallest image, whether the height of the selected tallest image is greater than the height of the currently enumerated image, and whether the sum of the widths of the selected tallest image and the currently enumerated image is less than or equal to the width of the rectangular area. If so, align the selected highest image with the top left corner of the current row, save the rectangular position of the selected highest image in the aggregate image, and mark it as processed; If not, align the current enumerated image with the top left corner of the current row, save the rectangular position of the current enumerated image in the aggregate graph, and mark it as processed.
5. The image processing method according to claim 4, characterized in that, Selective processing based on whether an image has been inserted in the current row of the rectangular area also includes: When an image has been inserted in the current row of the rectangular area, it is determined whether the difference between the width of the currently enumerated image and the width of the first image inserted in the current row is within a set range, and whether the sum of the heights of the images is less than or equal to the width of the first image inserted in the current row. If so, align the current enumerated image below the previous image already inserted in the current row, save the rectangular position of the current enumerated image in the aggregated image, and mark it as processed; If not, the remaining blank area of the current row is divided into a bottom rectangular area and a right rectangular area, and a recursive function is called to process the bottom rectangular area and the right rectangular area respectively.
6. The image processing method according to claim 5, characterized in that, When the current enumerated image has been processed and is the last image, the aggregated image is generated, including: Determine whether the currently enumerated image has been processed; If it has been processed, then determine whether the currently enumerated image is the last image; if it has not been processed, then proceed to determine whether no image has been inserted in the current row. If the currently enumerated image is the last image, then the aggregated image is generated; if the currently enumerated image is not the last image, then the next image is enumerated.
7. The image processing method according to claim 6, characterized in that, Before enumerating all images in descending order of width, the following steps are also included: Initialize the width of the aggregated image to the width of the widest image; Calculate the sum of the areas of all images and take the square root; If the sum of the width of the tallest image (excluding the widest image) and the width of the widest image is less than or equal to one-third of the square root, then the width of the aggregated image is set to twice the width of the widest image. If the sum of the width of the tallest image (excluding the widest image) and the width of the widest image is greater than one-third of the square root but less than or equal to the square root, then the width of the aggregated image is set to the sum of the width of the tallest image (excluding the widest image) and the width of the widest image.
8. An image processing device, characterized in that, It includes a processor and a memory, wherein the processor implements the image processing method as described in any one of claims 1 to 7 when executing a computer program stored in the memory.
9. A computer-readable storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the image processing method as described in any one of claims 1 to 7.