Background image generation method, device, medium and equipment suitable for different aspect ratios
By obtaining and scaling the head, middle and tail sections of the basic background image and splicing them together, the problem of background image deformation in scenes with different aspect ratios is solved, improving user experience and pattern continuity, and is suitable for complex businesses. need.
Patent Information
- Application Number
- CN202111535784.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-15
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2041-12-15
AI Technical Summary
When adding backgrounds to pictures or text, the existing technology is difficult to meet the needs of scenarios with different aspect ratios, causing the background graphics to become conspicuous and the user experience to be poor. Existing solutions such as scaling or fixed aspect ratios cannot effectively solve the problem. .
By obtaining the head, middle and tail pictures of the basic background picture, divide them according to the pattern repeating areas, and scale these pictures proportionally to ensure consistent sizes in the target direction. Calculate the number of middle pictures that need to be spliced, and perform splicing. Adapt to different aspect ratios to ensure pattern continuity and user experience.
It is possible to reduce the degree of stretching when generating background images in scenes with different aspect ratios, maintain user experience, and avoid destructive deformation of patterns, making it suitable for complex business scenarios.
Smart Images

Figure CN114281230B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, medium and equipment for generating background images suitable for different aspect ratios. Background Art
[0002] In Android development, we often encounter business scenarios where we need to add a background to a picture or a paragraph of text. In most cases, a PNG format picture (the picture needs to be stretched to a specified area) can meet the needs. However, the actual business scenarios are more complicated, and many backgrounds need to be implemented by developers themselves. For example, if you need to display some backgrounds with patterns, when the patterns are stretched or compressed too much (generally, this deformation is visible to the naked eye), it will produce a large deformation that affects the appearance.
[0003] For such scenarios, the existing solutions are usually the following:
[0004] 1) After scaling proportionally, cut off the excess parts;
[0005] 2) At the beginning of the design, fix the aspect ratio and use a proportional background image.
[0006] However, the solution of cropping the excess part after scaling proportionally will result in an incomplete background image; and the solution of using a fixed aspect ratio cannot meet product requirements due to the single aspect ratio. Then, as a second choice, using .9.PNG format images will cause the pattern in the stretching area to be stretched and deformed significantly, which will lead to a very poor user experience; and using a solid color background will have a single visual effect and it is difficult to meet personalized needs. Summary of the invention
[0007] The purpose of the embodiments of the present application is to provide a method, device, medium and equipment for generating background images suitable for different aspect ratios, so as to add background images to scenes with different aspect ratios while minimizing the degree of stretching and not affecting the user experience.
[0008] In order to achieve the above purpose, the embodiments of the present application are implemented in the following manner:
[0009] In a first aspect, an embodiment of the present application provides a method for generating background images suitable for different aspect ratios, comprising: obtaining a header image, a middle image, and a tail image obtained based on the division of a basic background image, wherein a pattern repeating region exists in the middle of the basic background image along a target direction, the target direction is any one of a width direction and a height direction of the basic background image, the middle image is part or all of the pattern repeating region, and two identical middle images are spliced in sequence along the target direction without destroying the continuity of the pattern in the spliced image; scaling the header image, the middle image, and the tail image proportionally to a size in a reference direction that is consistent with a size of a target background image in the reference direction, wherein the reference direction is another direction in the width direction and the height direction except the target direction; determining a target number of middle images to be spliced based on the size of the target background image in the target direction, and the sizes of the scaled header image, the scaled middle image, and the scaled tail image in the target direction; splicing the target background image based on the scaled header image and the scaled tail image, and the target number of scaled middle images.
[0010] In an embodiment of the present application, there is a pattern repeating area in the middle section of the basic background image along the target direction. The head section image, the middle section image (part or all of the pattern repeating area) and the tail section image obtained based on the division of the basic background image are used as the basis for splicing the target background image (the head section image, the middle section image and the tail section image need to be proportionally scaled to a size in the reference direction that is consistent with the size of the target background image in the reference direction). When two identical middle section images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed. Therefore, background images with different aspect ratios (target background images of different sizes can be spliced in the target direction) can be adapted by splicing different numbers of middle section images. Moreover, since the continuity of the pattern in the spliced image will not be destroyed, the background image gives the user a very smooth and non-abrupt feeling, which can ensure the user experience. By using the size of the target background image in the target direction, and the sizes of the scaled header image, the scaled middle image, and the scaled tail image in the target direction, the target number of middle images that need to be spliced can be determined, and the target background image can be spliced using the scaled header image, the scaled tail image, and the target number of scaled middle images. This allows the appropriate number of middle images to be used as reasonably as possible, reducing the size difference that needs to be made up when splicing the target background images (for example, by stretching or compressing each image). Therefore, the stretching deformation can be controlled within a small range (even to the point of no stretching or compression deformation), which users will hardly notice. Therefore, it can be well suited for business scenarios that require background images with different aspect ratios.
[0011] In combination with the first aspect, in a first possible implementation method of the first aspect, a header picture, a middle picture, and a tail picture obtained based on the division of a basic background picture are obtained, including: obtaining a basic background picture that needs to be suitable for a target aspect ratio, wherein the aspect ratio of the basic background picture is different from or the same as the target aspect ratio; determining a pattern repetition area in the basic background picture, wherein the pattern in the pattern repetition area is periodically repeated along the target direction; dividing the basic background picture into a header picture located on one side of the pattern repetition area, a tail picture located on the other side of the pattern repetition area, and a pending picture where the pattern repetition area is located, with the pattern repetition area as a boundary; and determining the middle picture based on the pending picture.
[0012] In this implementation, by obtaining a basic background image that needs to be suitable for the target aspect ratio (i.e., the aspect ratio of the target background image) (the aspect ratio of the basic background image is different from or the same as the target aspect ratio), a pattern repetition area is determined from the basic background image (the pattern in the area is periodically repeated along the target direction), and thus, with the pattern repetition area as the boundary, the basic background image is divided into a head segment image located on one side of the pattern repetition area, a tail segment image located on the other side of the pattern repetition area, and a pending image where the pattern repetition area is located, and the middle segment image is further determined based on the pending image. This method can divide the basic background image into a head segment image and a tail segment image on both sides that do not need to be repeatedly spliced, and a middle segment image that needs to be repeatedly spliced (determined based on the pending image), so that it can be ensured that the spliced target background image has a large commonality with the provided basic background image (the head segment and the tail segment are the same, and the middle segment has a middle segment image with different repetition times according to different aspect ratios), and the user experience will not be abrupt, which can ensure the user experience.
[0013] In combination with the first possible implementation method of the first aspect, in a second possible implementation method of the first aspect, the middle picture is determined based on the pending picture, including: determining a minimum repeating unit from the pattern repetition area of the pending picture, wherein a minimum repeating unit indicates that the pattern repetition area is repeated with this minimum repeating unit as a reference when extending along the target direction; and dividing a picture containing a minimum repeating unit or multiple consecutive minimum repeating units from the pending picture as the middle picture.
[0014] In this implementation, a minimum repeating unit is determined from the pattern repeating area of the pending picture (the pattern repeating area is repeated based on this minimum repeating unit when extending along the target direction); then a picture containing a minimum repeating unit or multiple consecutive minimum repeating units is divided from the pending picture as the middle picture. By dividing a minimum repeating unit as the middle picture, the middle picture can be adapted to a wider background picture as much as possible; and when multiple consecutive pictures of multiple minimum repeating units are used as the middle picture, when the size of the head picture and the tail picture in the target direction is much larger than the middle picture, blindly selecting a smaller middle picture will increase the workload of stitching pictures. Therefore, by using multiple consecutive pictures of multiple minimum repeating units as the middle picture, the efficiency of stitching pictures is effectively improved.
[0015] In combination with the first aspect, in a third possible implementation manner of the first aspect, based on the size of the target background image in the target direction, and the sizes of the scaled head image, the scaled middle image, and the scaled tail image in the target direction, determining the target number of middle images that need to be spliced includes: calculating the target number of middle images that need to be spliced using the following rounding formula:
[0016] centerImageCount=(bllh-th-bh) / ch,
[0017] Among them, centerImageCount represents the number of targets, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction.
[0018] In this implementation, the target number of the middle-segment pictures that need to be spliced is calculated using the provided rounding formula, so that the target number of the middle-segment pictures that need to be spliced can be determined simply and reliably.
[0019] In combination with the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, based on the scaled header image and the scaled tail image, and the target number of scaled middle images, splicing the target background image includes: using the following remainder formula to calculate the margin size required to be compensated for splicing the target background image with the scaled header image and the scaled tail image, and the target number of scaled middle images:
[0020] spareH=(bllh-th-bh)%ch,
[0021] Among them, spareH represents the margin size; the scaled header image, the target number of scaled middle images, and the scaled tail images are sequentially spliced along the target direction; the scaled header image or the scaled tail image is stretched by spareH along the target direction, or the scaled header image and the scaled tail image are stretched as a whole by spareH along the target direction to obtain the spliced target background image.
[0022] In this implementation, the provided remainder formula can be used to simply and reliably calculate the margin size required to compensate for the spliced target background image, and then the margin size is allocated to the scaled header image and / or the scaled tail image (the margin size is compensated by stretching the scaled header image and / or the scaled tail image), which will not affect the continuity and repeatability of the pattern after the middle images are spliced together. In addition, due to the special positions of the header image and the tail image (especially the tail image), this margin size is allocated to them, and the user himself is difficult to notice, so it will hardly affect the user experience.
[0023] In combination with the first aspect, in a fifth possible implementation manner of the first aspect, based on the size of the target background image in the target direction, and the sizes of the scaled head image, the scaled middle image, and the scaled tail image in the target direction, determining the target number of middle images to be spliced includes:
[0024] Use the following rounding formula to calculate the number of undetermined middle images that need to be spliced:
[0025] centerImageCount'=(bllh-th-bh) / ch,
[0026] Among them, centerImageCount' represents the undetermined number, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction;
[0027] The following remainder formula is used to calculate the margin size required to be compensated for splicing the target background image with the scaled head segment image, the scaled tail segment image, and a to-be-determined number of scaled middle segment images:
[0028] spareH=(bllh-th-bh)%ch,
[0029] Wherein, spareH represents the spare size;
[0030] Use spareH with Make comparisons;
[0031] like The target number centerImageCount is obtained by adding one to the undetermined number centerImageCount', and the compensation size compensateH=ch-spareH is determined;
[0032] like The undetermined number centerImageCount' is determined as the target number centerImageCount.
[0033] In this implementation, by comparing the margin size with half of the size of the scaled middle image in the target direction, it is determined whether to fill this part of the margin size by stretching or to eliminate this part of the compensation size by compression. In this way, the method with the smallest adjustment amount can be selected to minimize the degree of stretching or compression deformation of the pattern in the target background image, making it more difficult for users to perceive such deformation, thereby ensuring user experience.
[0034] In combination with the fifth possible implementation of the first aspect, in a sixth possible implementation of the first aspect, based on the scaled head segment image and the scaled tail segment image, and the target number of scaled middle segment images, the target background image is stitched together, including: for : sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail images along the target direction; compress the scaled header image or the tail image by compensateH along the target direction, or compress the scaled header image and the scaled tail image as a whole along the target direction by compensateH to obtain the spliced target background image; for Situation: sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail images along the target direction; stretch the scaled header image or the scaled tail image by spareH along the target direction, or stretch the scaled header image and the scaled tail image as a whole by spareH along the target direction to obtain the spliced target background image.
[0035] In this implementation, for different situations ( or ), and adopt the corresponding image stitching method, so as to ensure the coordination of the stitched target background image as much as possible and ensure the user experience.
[0036] In a second aspect, an embodiment of the present application provides a background image generation device suitable for different aspect ratios, including: an acquisition unit, used to acquire a header image, a middle image, and a tail image obtained based on the division of a basic background image, wherein the middle image of the basic background image has a pattern repeating region along a target direction, and the target direction is any one of the width direction and the height direction of the basic background image, the middle image is part or all of the pattern repeating region, and when two identical middle images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed; a scaling unit, used to scale the header image, the middle image, and the tail image respectively. The picture is proportionally scaled until its size in a reference direction is consistent with the size of the target background picture in the reference direction, wherein the reference direction is another direction of the width direction and the height direction except the target direction; a calculation unit is used to determine the target number of middle-segment pictures that need to be spliced based on the size of the target background picture in the target direction, and the sizes of the scaled head segment picture, the scaled middle segment picture, and the scaled tail segment picture in the target direction; a splicing unit is used to splice the target background picture based on the scaled head segment picture and the scaled tail segment picture, and the target number of scaled middle segment pictures.
[0037] In a third aspect, an embodiment of the present application provides a storage medium, which includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the method for generating background images suitable for different aspect ratios described in any one of the first aspect or possible implementation methods of the first aspect.
[0038] In a fourth aspect, an embodiment of the present application provides a terminal device comprising a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions, and when the program instructions are loaded and executed by the processor, the method for generating background images suitable for different aspect ratios described in any one of the first aspect or the possible implementation methods of the first aspect is implemented.
[0039] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other unrelated drawings can be obtained based on these drawings without paying creative labor.
[0041] Figure 1A flowchart of a method for generating background images with different aspect ratios provided in an embodiment of the present application.
[0042] Figure 2 A schematic diagram of a basic background image provided in an embodiment of the present application.
[0043] Figure 3 A schematic diagram of dividing a basic background image into a head image, a middle image, and a tail image.
[0044] Figure 4 Schematic diagram of the process of stitching the target background image based on the first method.
[0045] Figure 5 Schematic diagram of the process of stitching the target background image based on the second method.
[0046] Figure 6 A structural block diagram of a background image generation device suitable for different aspect ratios provided in an embodiment of the present application.
[0047] Figure 7 A structural block diagram of a terminal device provided in an embodiment of the present application.
[0048] Icons: 10 - device for generating background images suitable for different aspect ratios; 11 - acquisition unit; 12 - scaling unit; 13 - calculation unit; 14 - stitching unit; 20 - terminal device; 21 - memory; 22 - communication module; 23 - bus; 24 - processor. DETAILED DESCRIPTION
[0049] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0050] In this embodiment, the method for generating background images suitable for different aspect ratios can be applied in a terminal device to adapt target background images with different aspect ratios to scenes with different aspect ratio requirements.
[0051] See also Figure 1 , Figure 1 A flowchart of a method for generating background images with different aspect ratios provided in an embodiment of the present application. In this embodiment, the method for generating background images with different aspect ratios may include step S10, step S20, step S30 and step S40.
[0052] When it is necessary to add a background image for a business scenario, for the convenience of description, in this embodiment, the height and width applicable to the background image are used as the target aspect ratio. Therefore, this solution needs to provide a target background image that meets its height and width (target aspect ratio).
[0053] Based on this, the terminal device can execute step S10.
[0054] Step S10: Obtain a head image, a middle image and a tail image based on the division of a basic background image, wherein the middle image of the basic background image has a pattern repeating region along a target direction, the target direction is any one of a width direction and a height direction of the basic background image, the middle image is part or all of the pattern repeating region, and when two identical middle images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed.
[0055] In an embodiment of the present application, a terminal device can obtain a head segment image, a middle segment image, and a tail segment image obtained based on the division of a basic background image. Among them, the middle segment of the basic background image has a pattern repeating region along the target direction (either the width direction or the height direction of the basic background image), the middle segment image is part or all of the pattern repeating region (usually a part is taken, but the whole of the pattern repeating region is not excluded), and when two identical middle segment images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed.
[0056] Exemplarily, the terminal device may obtain a basic background image that needs to be suitable for the target aspect ratio, wherein the aspect ratio of the basic background image is different from or the same as the target aspect ratio, that is, the two are independent of each other and do not need to have a correlation in size and aspect ratio.
[0057] like Figure 2 As shown, the middle segment in the basic background image (i.e., the first and last parts in the non-target direction) is along the target direction ( Figure 2 The height direction of the basic background image is shown as the target direction. This is taken as an example and is not limited to this.) There is a pattern repetition area, and the pattern in the pattern repetition area is periodically repeated along the target direction.
[0058] Based on this, the terminal device can determine the pattern repetition area in the basic background image, and then divide the basic background image into a head segment image located on one side (the first side, i.e., the upper side) of the pattern repetition area, a tail segment image located on the other side (the tail side, i.e., the lower side) of the pattern repetition area, and a pending image where the pattern repetition area is located, based on the pattern repetition area. Then, the middle segment image can be further determined based on the pending image.
[0059] By obtaining a basic background image (the aspect ratio of the basic background image is different from or the same as the target aspect ratio) that needs to be suitable for the target aspect ratio (i.e., the aspect ratio of the target background image), a pattern repetition area is determined from the basic background image (the pattern in the area is periodically repeated along the target direction), and thus, with the pattern repetition area as the boundary, the basic background image is divided into a head segment image located on one side of the pattern repetition area, a tail segment image located on the other side of the pattern repetition area, and a pending image where the pattern repetition area is located, and the middle segment image is further determined based on the pending image. This method can divide the basic background image into a head segment image and a tail segment image on both sides that do not need to be repeatedly spliced, and a middle segment image that needs to be repeatedly spliced (determined based on the pending image), thereby ensuring that the spliced target background image has a large commonality with the provided basic background image (the head segment and the tail segment are the same, and the middle segment has a middle segment image with different repetition times according to different aspect ratios), and the user experience will not be abrupt, which can ensure the user experience.
[0060] Specifically, the terminal device may further determine a minimum repeating unit from the pattern repeating region of the pending picture, where a minimum repeating unit means that the pattern repeating region is repeated based on the minimum repeating unit when extending along the target direction. Then, the terminal device may divide a picture containing a minimum repeating unit or multiple consecutive minimum repeating units from the pending picture as the middle picture.
[0061] For example, in the case where the size of a minimum repeating unit is particularly small, for example, the size of the minimum repeating unit is only the larger size of the first and last pictures. the following, In the following, a plurality of consecutive minimum repeating unit pictures can be determined as the middle pictures (for example, 4, 5, 8, 10, etc.). For the case where the size of a minimum repeating unit is not particularly small, for example, the size of the minimum repeating unit is only the larger size of the first picture and the last picture. above, As mentioned above, a picture containing a minimum repeating unit can be divided from the pending picture as the middle picture.
[0062] By dividing a minimum repeating unit as the middle picture, the middle picture can be adapted to a wider background picture as much as possible; and when multiple consecutive minimum repeating unit pictures are used as the middle picture, when the sizes of the head picture and the tail picture in the target direction are much larger than the middle picture, blindly selecting a smaller middle picture will increase the workload of stitching pictures. Therefore, by using multiple consecutive minimum repeating unit pictures as the middle picture, the efficiency of stitching pictures is effectively improved.
[0063] It should be noted that the specific method of dividing the basic background picture in the present embodiment to obtain the header picture, the middle picture and the tail picture can be determined by the user performing certain auxiliary operations, for example, determining the positions of the divided pictures (header picture, middle picture, tail picture, pending picture, etc.), thereby dividing the header picture, the middle picture and the tail picture. Of course, it can also be obtained by the terminal device through intelligent division by image recognition and image segmentation. For example, by performing contour detection on the basic background picture, detecting the starting point and the end point of the pattern repetition area in the target direction, the basic background picture is divided into the header picture, the pending picture and the tail picture; then, the starting point and the end point of each repeated pattern are further determined by contour matching, so as to separate the middle picture from the pending picture. Therefore, the specific method used when dividing the basic background picture into the header picture, the middle picture and the tail picture should not be regarded as a limitation of the present application. Based on the division of the basic background picture, the header picture, the middle picture and the tail picture are obtained, such as Figure 3 shown.
[0064] After obtaining the head picture, the middle picture and the tail picture obtained based on the division of the basic background picture, the terminal device may execute step S20.
[0065] Step S20: Scale the head picture, the middle picture and the tail picture proportionally to the size in the reference direction to be consistent with the size of the target background picture in the reference direction, wherein the reference direction is another direction of the width direction and the height direction except the target direction.
[0066] In this embodiment, the terminal device can scale the head picture, the middle picture, and the tail picture in equal proportions to make the size in the reference direction consistent with the size of the target background picture in the reference direction, where the reference direction is another direction in the width direction and the height direction except the target direction. Figure 2 , taking the height direction of the basic background image as the target direction, then the width direction of the basic background image is the reference direction (the same is true for the target background image).
[0067] After scaling the head picture, the middle picture, and the tail picture in equal proportions to have a size in the reference direction that is consistent with the size of the target background picture in the reference direction, the terminal device may execute step S30.
[0068] Step S30: Determine the target number of middle pictures to be spliced based on the size of the target background picture in the target direction and the sizes of the scaled head picture, scaled middle picture and scaled tail picture in the target direction.
[0069] In this embodiment, the terminal device can determine the target number of middle pictures that need to be spliced based on the size of the target background picture in the target direction, and the sizes of the scaled head picture, scaled middle picture and scaled tail picture in the target direction.
[0070] Exemplarily, this embodiment introduces two methods for determining the target quantity.
[0071] First, in the first method, the terminal device can use the following rounding formula to calculate the target number of mid-segment images that need to be spliced:
[0072] centerImageCount=(bllh-th-bh) / ch, (1)
[0073] Among them, centerImageCount represents the number of targets, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction.
[0074] By using the rounding formula provided in the first method to calculate the target number of the middle pictures that need to be spliced, the target number of the middle pictures that need to be spliced can be determined simply and reliably.
[0075] Secondly, in the second method, the terminal device can use the following rounding formula provided to calculate the pending number of middle pictures that need to be spliced:
[0076] centerImageCount'=(bllh-th-bh) / ch, (2)
[0077] Among them, centerImageCount' represents the undetermined number, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction.
[0078] Then, the terminal device can use the following modulo formula to calculate the margin size required to be compensated for stitching the target background image with the scaled head segment image, the scaled tail segment image, and a to-be-determined number of scaled middle segment images:
[0079] spareH=(bllh-th-bh)%ch, (3)
[0080] Wherein, spareH represents the spare size.
[0081] The terminal device can then use spareH with For comparison:
[0082] like The terminal device can add one to the pending number centerImageCount' to obtain the target number centerImageCount, that is:
[0083] centerImageCount=centerImageCount'+1, (4)
[0084] Then further determine the compensation size compensateH:
[0085] compensateH=ch-spareH. (5)
[0086] like The terminal device may determine the pending number centerImageCount' as the target number centerImageCount, that is:
[0087] centerImageCount=centerImageCount', (6)
[0088] In this case, there is no need to determine the compensation dimension compensateH, but instead the spare dimension spareH is used.
[0089] By comparing the margin size with half of the size of the scaled middle image in the target direction, it is determined whether to fill this part of the margin size by stretching or to eliminate this part of the compensation size by compression. In this way, the method with the smallest adjustment amount can be selected to minimize the stretching deformation or compression deformation of the pattern in the target background image, making it more difficult for users to perceive such deformation, thereby ensuring user experience.
[0090] After determining the target number of middle-segment images that need to be spliced, the terminal device may execute step S40.
[0091] Step S40: splicing the target background image based on the scaled head segment image, the scaled tail segment image, and a target number of scaled middle segment images.
[0092] In this embodiment, the terminal device can splice a target background image that meets the target aspect ratio based on the scaled head segment image, the scaled tail segment image, and the target number of scaled middle segment images.
[0093] For example, since different methods are used to determine the number of targets, the methods of splicing the target background images may be different. Therefore, this solution also introduces the methods of splicing the target background images from two situations.
[0094] For the target number of middle-segment images to be spliced determined in the first way, the terminal device can use the following modulo formula provided to calculate the margin size required to be compensated for splicing the target background image with the scaled head-segment image, the scaled tail-segment image, and the target number of scaled middle-segment images:
[0095] spareH=(bllh-th-bh)%ch, (7)
[0096] Among them, spareH represents the spare size.
[0097] Then, the terminal device can sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail image along the target direction. Then, the scaled header image or the scaled tail image can be stretched by spareH along the target direction to obtain the spliced target background image. Alternatively, the scaled header image and the scaled tail image are stretched by spareH as a whole along the target direction to obtain the spliced target background image. Alternatively, the scaled header image, the target number of scaled middle images, and the scaled tail image are stretched by spareH as a whole along the target direction to obtain the spliced target background image. The process of splicing the target background images in this way is as follows. Figure 4 shown.
[0098] The provided remainder formula can be used to simply and reliably calculate the margin size required to compensate for the target background image to be spliced, and then the margin size is allocated to the scaled header image and / or the scaled tail image (the margin size is compensated by stretching the scaled header image and / or the scaled tail image), which will not affect the continuity and repeatability of the pattern after the middle image is spliced. In addition, due to the special positions of the header image and the tail image (especially the tail image), the margin size is allocated to them, and the user itself is difficult to detect, so it will hardly affect the user experience. In addition, the scaled header image, the scaled middle images of the target number of spliced images, and the scaled tail image are stretched as a whole along the target direction, so that the margin size can be allocated to each sub-image (the header image, each middle image, the tail image, etc.), which can minimize the stretching deformation.
[0099] It should be noted that when stitching pictures, the margin size can also be first allocated to the scaled head picture and / or the scaled tail picture, and then stitching is performed, whichever method is more convenient in practice, and is not limited here. Of course, for the method of allocating the margin size to each sub-picture, it is necessary to first stitch and then stretch, and there is no need to calculate the specific size of the margin size allocated to each sub-picture.
[0100] With respect to the target number of the middle pictures to be spliced determined in the second manner, the terminal device may adopt different manners based on two different situations:
[0101] First, for Situation:
[0102] The terminal device can sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail image along the target direction, and then compress the scaled header image or the tail image along the target direction by compensateH to obtain the spliced target background image. Alternatively, the scaled header image and the scaled tail image are compressed as a whole along the target direction by compensateH to obtain the spliced target background image. Alternatively, the scaled header image, the target number of scaled middle images, and the scaled tail image are compressed as a whole along the target direction by compensateH to obtain the spliced target background image. The process of splicing the target background images in this way is as follows. Figure 5 shown.
[0103] Secondly, for Situation:
[0104] The terminal device can sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail image along the target direction, and then stretch the scaled header image or the scaled tail image by spareH along the target direction to obtain the spliced target background image. Alternatively, the scaled header image and the scaled tail image are stretched by spareH as a whole along the target direction to obtain the spliced target background image. Alternatively, the scaled header image, the target number of scaled middle images, and the scaled tail image are stretched by spareH as a whole along the target direction to obtain the spliced target background image. The process of splicing the target background images in this way is as follows. Figure 4 shown.
[0105] For different situations ( or ), and adopt the corresponding image stitching method, so as to ensure the coordination of the stitched target background image as much as possible and ensure the user experience.
[0106] To facilitate understanding, this embodiment provides a practical example to illustrate the application of the method for generating background images suitable for different aspect ratios.
[0107] First, a basic background image can be obtained. This basic background image can be a background image selected by a developer, or a basic background image obtained from a background image library (wherein the middle section of the basic background image has a pattern repeating area along the target direction), which is not limited here.
[0108] Then, the basic background image can be segmented according to the needs to obtain three images: a head image, a middle image and a tail image. The middle image is part or all of the pattern repeating area, and when two identical middle images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed.
[0109] After that, you can inherit the native Android class LinearLayout and implement your own BackgroundLinearLayout. The height of BackgroundLinearLayout is bllh. The responsibility of this custom View is to draw the background image according to its own width and height, which can be used to determine the width and height (target aspect ratio) of the target background image.
[0110] Further, the widths of the header, middle, and tail images can be proportionally scaled to the width of BackgroundLinearLayout to obtain the scaled top image height th, bottom image height bh, and middle image height ch. Then the number of middle images required is calculated based on th, bh, ch, and bllh, centerImageCount = (bllh-th-bh) / ch. Among them, if centerImageCount is a decimal (i.e., it cannot be divided evenly), spareH = (bllh-th-bh)% ch, and spareH is the remainder obtained (i.e., the margin size).
[0111] From top to bottom, first draw the header image, then loop through the middle image according to th, ch, and centerImageCount, and finally draw the tail image. If spareH is not 0, you can scale the height of the base image to bh+spareH before drawing, which will cause the base image to stretch slightly. You can also allocate spareH to the height of other images or the height of all images. In this way, you can achieve the splicing and drawing of the target background image.
[0112] In addition, it should be noted that the method for generating background images applicable to different aspect ratios in this embodiment describes the basic background image as follows: there is a pattern repetition area in the middle section of the basic background image along the target direction (that is, all patterns in this area are repeated, and there is no requirement for color. Whether to limit the color can be determined according to actual conditions, as long as the target basic image to be spliced is coordinated as a whole and the transition at the joint is natural), but it is not limited to this. In practical applications, there may also be some irregular fine structures that are not required to be strictly repeated, such as irregular sawtooth edges (the interval between each sawtooth does not exceed 2mm), which can also be processed as the basic background image for the method for generating background images applicable to different aspect ratios provided in this embodiment to splice the target background image.
[0113] See also Figure 6 , Figure 6 This is a structural block diagram of a background image generation device 10 applicable to different aspect ratios provided in an embodiment of the present application. In this embodiment, the background image generation device 10 applicable to different aspect ratios may include:
[0114] The acquisition unit 11 is used to acquire a head segment image, a middle segment image and a tail segment image obtained based on the division of a basic background image, wherein the middle segment of the basic background image has a pattern repetition area along a target direction, the target direction is any one of a width direction and a height direction of the basic background image, the middle segment image is part or all of the pattern repetition area, and when two identical middle segment images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed.
[0115] The scaling unit 12 is used to scale the head picture, the middle picture and the tail picture in equal proportion to the size in the reference direction to be consistent with the size of the target background picture in the reference direction, wherein the reference direction is another direction of the width direction and the height direction except the target direction.
[0116] The calculation unit 13 is used to determine the target number of middle-segment images to be spliced based on the size of the target background image in the target direction and the sizes of the scaled head segment image, the scaled middle segment image and the scaled tail segment image in the target direction.
[0117] The splicing unit 14 is used to splice the target background image based on the scaled head segment image, the scaled tail segment image, and the target number of scaled middle segment images.
[0118] In this embodiment, the acquisition unit 11 is specifically used to: acquire a basic background image that needs to be suitable for the target aspect ratio, wherein the aspect ratio of the basic background image is different from or the same as the target aspect ratio; determine a pattern repetition area in the basic background image, wherein the pattern in the pattern repetition area is periodically repeated along the target direction; using the pattern repetition area as a boundary, divide the basic background image into a head segment image located on one side of the pattern repetition area, a tail segment image located on the other side of the pattern repetition area, and a pending image where the pattern repetition area is located; and determine the middle segment image based on the pending image.
[0119] In this embodiment, the acquisition unit 11 is specifically used to: determine a minimum repeating unit from the pattern repetition area of the pending image, wherein a minimum repeating unit indicates that the pattern repetition area is repeated based on this minimum repeating unit when extending along the target direction; and divide a picture containing a minimum repeating unit or multiple consecutive minimum repeating units from the pending image as the middle picture.
[0120] In this embodiment, the calculation unit 13 is specifically used to calculate the target number of middle-segment images to be spliced using the following rounding formula:
[0121] centerImageCount=(bllh-th-bh) / ch,
[0122] Among them, centerImageCount represents the number of targets, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction.
[0123] In this embodiment, the splicing unit 14 is used to calculate the margin size required to be compensated for splicing the target background image with the scaled head segment image, the scaled tail segment image, and the target number of scaled middle segment images using the following remainder formula:
[0124] spareH=(bllh-th-bh)%ch,
[0125] Wherein, spareH represents the spare size;
[0126] Sequentially splicing the scaled head segment image, the target number of scaled middle segment images, and the scaled tail segment images along the target direction;
[0127] The scaled head segment picture or the scaled tail segment picture is stretched by spareH along the target direction, or the scaled head segment picture and the scaled tail segment picture are stretched by spareH as a whole along the target direction to obtain the spliced target background picture.
[0128] In this embodiment, the calculation unit 13 may also be used to calculate the undetermined number of middle-segment images to be spliced using the following rounding formula:
[0129] centerImageCount'=(bllh-th-bh) / ch,
[0130] Among them, centerImageCount' represents the undetermined number, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head segment image in the target direction, ch represents the size of the scaled middle segment image in the target direction, and bh represents the size of the scaled tail segment image in the target direction; the following remainder formula is used to calculate the margin size required to be compensated for splicing the target background image with the scaled head segment image, the scaled tail segment image, and the undetermined number of scaled middle segment images:
[0131] spareH=(bllh-th-bh)%ch,
[0132] Wherein, spareH represents the margin size; spareH and For comparison; if The target number centerImageCount is obtained by adding one to the undetermined number centerImageCount', and the compensation size compensateH=ch-spareH is determined; if The undetermined number centerImageCount' is determined as the target number centerImageCount.
[0133] In this embodiment, the splicing unit 14 is used for:
[0134] against Case: sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail images along the target direction; compress the scaled header image or the tail image by compensateH along the target direction, or compress the scaled header image and the scaled tail image as a whole along the target direction by compensateH to obtain the spliced target background image;
[0135] against Situation: sequentially splice the scaled header image, the target number of scaled middle images, and the scaled tail images along the target direction; stretch the scaled header image or the scaled tail image by spareH along the target direction, or stretch the scaled header image and the scaled tail image as a whole by spareH along the target direction to obtain the spliced target background image.
[0136] See also Figure 7 , Figure 7 A structural block diagram of a terminal device 20 provided in an embodiment of the present application.
[0137] In this embodiment, the terminal device 20 may be a smart terminal such as a personal computer, a tablet computer, or a smart phone, which is not limited here.
[0138] Exemplarily, the terminal device 20 may include: a communication module 22 connected to the outside world through a network, one or more processors 24 for executing program instructions, a bus 23, and different forms of memory 21, such as a disk, ROM, or RAM, or any combination thereof. In addition, the terminal device 20 also has a display screen that can display the generated target background image. The memory 21, the communication module 22, and the processor 24 can be connected through the bus 23.
[0139] Exemplarily, programs are stored in the memory 21. The processor 24 can call and run these programs from the memory 21, so that the background image generation method applicable to different aspect ratios can be implemented by running the programs.
[0140] An embodiment of the present application further provides a storage medium, which includes a stored program, wherein when the program is run, the device where the storage medium is located is controlled to execute the background image generation method applicable to different aspect ratios of this embodiment.
[0141] In summary, the embodiments of the present application provide a method, device, medium and equipment for generating background images suitable for different aspect ratios. There is a pattern repeating area in the middle section of the basic background image along the target direction. The header image, the middle image (part or all of the pattern repeating area) and the tail image obtained based on the division of the basic background image are used as the basis for splicing the target background image (the header image, the middle image and the tail image need to be proportionally scaled to a size in the reference direction that is consistent with the size of the target background image in the reference direction). When two identical middle images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed. Therefore, background images with different aspect ratios (target background images of different sizes can be spliced in the target direction) can be adapted by splicing different numbers of middle images. Moreover, since the continuity of the pattern in the spliced image will not be destroyed, the background image gives the user a very smooth and non-abrupt feeling, which can ensure the user experience. By using the size of the target background image in the target direction, and the sizes of the scaled header image, the scaled middle image, and the scaled tail image in the target direction, the target number of middle images that need to be spliced can be determined, and the target background image can be spliced using the scaled header image, the scaled tail image, and the target number of scaled middle images. This allows the appropriate number of middle images to be used as reasonably as possible, reducing the size difference that needs to be made up when splicing the target background images (for example, by stretching or compressing each image). Therefore, the stretching deformation can be controlled within a small range (even to the point of no stretching or compression deformation), which users will hardly notice. Therefore, it can be well suited for business scenarios that require background images with different aspect ratios.
[0142] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are only exemplary. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0143] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0144] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for generating background images suitable for different aspect ratios, characterized in that: include: Obtaining a head segment image, a middle segment image, and a tail segment image obtained based on the division of the basic background image, wherein the middle segment of the basic background image has a pattern repeating region along a target direction, the target direction is any one of a width direction and a height direction of the basic background image, the middle segment image is part or all of the pattern repeating region, and when two identical middle segment images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed; Respectively scaling the head picture, the middle picture, and the tail picture in equal proportions to have their sizes in a reference direction consistent with the size of the target background picture in the reference direction, wherein the reference direction is another direction of the width direction and the height direction except the target direction; Determine the target number of middle-segment images to be spliced based on the size of the target background image in the target direction and the sizes of the scaled head segment image, the scaled middle segment image, and the scaled tail segment image in the target direction; Based on the scaled head segment image and the scaled tail segment image, and the target number of scaled middle segment images, stitching out the target background image; The step of obtaining the head picture, the middle picture and the tail picture obtained based on the division of the basic background picture includes: Acquire a basic background image that needs to be suitable for a target aspect ratio, wherein the aspect ratio of the basic background image is different from or the same as the target aspect ratio; determine a pattern repetition region in the basic background image, wherein the pattern in the pattern repetition region is periodically repeated along the target direction; divide the basic background image into a head segment image located on one side of the pattern repetition region, a tail segment image located on the other side of the pattern repetition region, and a pending image where the pattern repetition region is located, based on the pending image; determine the middle segment image based on the pending image; Wherein, based on the pending picture, determining the middle picture includes: Determine a minimum repeating unit from the pattern repeating region of the pending picture, wherein a minimum repeating unit means that the pattern repeating region is repeated based on the minimum repeating unit when extending along the target direction; divide a picture containing a minimum repeating unit or a plurality of consecutive minimum repeating units from the pending picture as the middle picture; Wherein, based on the size of the target background image in the target direction, and the sizes of the scaled head segment image, the scaled middle segment image, and the scaled tail segment image in the target direction, determining the target number of middle segment images to be spliced includes: Use the following rounding formula to calculate the target number of mid-segment images that need to be stitched: centerImageCount=(bllh-th-bh) / ch, Among them, centerimageCount represents the number of targets, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction; Alternatively, based on the size of the target background image in the target direction, and the sizes of the scaled head image, the scaled middle image, and the scaled tail image in the target direction, determining the target number of middle images to be spliced includes: Use the following rounding formula to calculate the number of undetermined middle images that need to be spliced: centerImageCount'=(bllh-th-bh) / ch, Among them, centerImageCount' represents the undetermined number, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction; The following remainder formula is used to calculate the margin size required to be compensated for splicing the target background image with the scaled head segment image, the scaled tail segment image, and a to-be-determined number of scaled middle segment images: spareH=(bllh-th-bh)%ch, Wherein, spareH represents the spare size; Use spareH with Make comparisons; like The target number centerImageCount is obtained by adding one to the undetermined number centerImageCount', and the compensation size compensateH=ch-spareH is determined; like The undetermined number centerImageCount' is determined as the target number centerImageCount.
2. The method for generating background images applicable to different aspect ratios according to claim 1, characterized in that: Based on the scaled head segment image and the scaled tail segment image, and the target number of scaled middle segment images, the target background image is stitched together, including: The following remainder formula is used to calculate the margin size required to be compensated for splicing the target background image with the scaled head segment image, the scaled tail segment image, and the target number of scaled middle segment images: spareH=(bllh-th-bh)%ch, Wherein, spareH represents the spare size; Sequentially splicing the scaled head segment image, the target number of scaled middle segment images, and the scaled tail segment images along the target direction; The scaled head segment picture or the scaled tail segment picture is stretched by spareH along the target direction, or the scaled head segment picture and the scaled tail segment picture are stretched by spareH as a whole along the target direction to obtain the spliced target background picture.
3. The method for generating background images applicable to different aspect ratios according to claim 1, characterized in that: Based on the scaled head segment image and the scaled tail segment image, and the target number of scaled middle segment images, the target background image is stitched together, including: against Situation: Sequentially splicing the scaled head segment image, the target number of scaled middle segment images, and the scaled tail segment images along the target direction; Compressing the scaled header image or tail image by compensationH along the target direction, or compressing the scaled header image and the scaled tail image as a whole by compensationH along the target direction to obtain the spliced target background image; against Situation: Sequentially splicing the scaled head segment image, the target number of scaled middle segment images, and the scaled tail segment images along the target direction; The scaled head segment picture or the scaled tail segment picture is stretched by spareH along the target direction, or the scaled head segment picture and the scaled tail segment picture are stretched by spareH as a whole along the target direction to obtain the spliced target background picture.
4. A background image generation device suitable for different aspect ratios, characterized in that: include: An acquisition unit is used to acquire a head segment image, a middle segment image, and a tail segment image obtained based on the division of a basic background image, wherein the middle segment of the basic background image has a pattern repeating region along a target direction, the target direction is any one of a width direction and a height direction of the basic background image, the middle segment image is part or all of the pattern repeating region, and when two identical middle segment images are spliced in sequence along the target direction, the continuity of the pattern in the spliced image is not destroyed; A scaling unit, used to scale the head picture, the middle picture and the tail picture in equal proportions to make their sizes in a reference direction consistent with the size of the target background picture in the reference direction, wherein the reference direction is another direction of the width direction and the height direction except the target direction; A calculation unit, configured to determine a target number of middle-segment images to be spliced based on a size of a target background image in the target direction, and sizes of the scaled head-segment image, the scaled middle-segment image, and the scaled tail-segment image in the target direction; A splicing unit, configured to splice the target background image based on the scaled head segment image, the scaled tail segment image, and a target number of scaled middle segment images; The acquisition unit is specifically used to: acquire a basic background image that needs to be suitable for a target aspect ratio, wherein the aspect ratio of the basic background image is different from or the same as the target aspect ratio; determine a pattern repetition region in the basic background image, wherein the pattern in the pattern repetition region is periodically repeated along the target direction; divide the basic background image into a head segment image located on one side of the pattern repetition region, a tail segment image located on the other side of the pattern repetition region, and a pending image where the pattern repetition region is located, with the pattern repetition region as a boundary; determine the middle segment image based on the pending image; The acquisition unit is specifically used to: determine a minimum repeating unit from the pattern repeating area of the pending picture, wherein a minimum repeating unit means that the pattern repeating area is repeated based on the minimum repeating unit when extending along the target direction; divide a picture containing a minimum repeating unit or multiple consecutive minimum repeating units from the pending picture as the middle picture; The calculation unit is specifically used to calculate the target number of the middle segment images to be spliced using the following rounding formula: centerImageCount=(bllh-th-bh) / ch, Among them, centerImageCount represents the number of targets, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head image in the target direction, ch represents the size of the scaled middle image in the target direction, and bh represents the size of the scaled tail image in the target direction; Alternatively, the calculation unit is specifically used to calculate the pending number of middle-segment images to be spliced using the following rounding formula: centerImageCount'=(bllh-th-bh) / ch, Among them, centerImageCount' represents the undetermined number, bllh represents the size of the target background image in the target direction, th represents the size of the scaled head segment image in the target direction, ch represents the size of the scaled middle segment image in the target direction, and bh represents the size of the scaled tail segment image in the target direction; the following remainder formula is used to calculate the margin size required to be compensated for splicing the target background image with the scaled head segment image, the scaled tail segment image, and the undetermined number of scaled middle segment images: spareH=(bllh-th-bh)%ch, Wherein, spareH represents the margin size; spareH and For comparison; if The target number centerImageCount is obtained by adding one to the undetermined number centerImageCount', and the compensation size compensateH=ch-spareH is determined; if The undetermined number centerImageCount' is determined as the target number centerImageCount.
5. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the background image generation method applicable to different aspect ratios as described in any one of claims 1 to 3.
6. A terminal device, characterized in that: The method comprises a memory and a processor, wherein the memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions. When the program instructions are loaded and executed by the processor, the method for generating background images suitable for different aspect ratios according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Method and device for processing image of mobile terminal equipment
CN105447815A
Multi-operator image redirection method for maintaining important content area width-to-height ratio
CN107330885A
Image adaptation method, electronic equipment and storage medium
CN110738598A
Picture scaling method, device and equipment and storage medium
CN111738917A
Image processing method
JP2013219840A
