Image processing method and device, electronic equipment and storage medium

By calculating the edge pixel coverage area ratio and color transition of the rounded image, the aliasing effect problem in traditional rendering methods is solved, and the visual effect and computational efficiency of the image are improved.

CN120689458APending Publication Date: 2025-09-23GREAT WALL MOTOR CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510657727.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-21
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

Traditional image rendering methods produce jagged effects when processing rounded corner images, which affects the visual effect and increases the burden on the graphics processor.

Method used

By determining the geometric relationship between the vector path of the rounded image and the bitmap pixels, calculating the area ratio of the edge pixels covered by the vector path, and dynamically adjusting the fill color in combination with the edge color and background color, a smooth transition is achieved.

Benefits of technology

The aliasing effect is reduced, the use of computing resources is optimized, and visual smoothness and rendering efficiency are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120689458A_ABST
    Figure CN120689458A_ABST
Patent Text Reader

Abstract

The invention provides an image processing method and device, electronic equipment and a storage medium. According to the method, the area proportion of each edge pixel covered by a vector path is determined through the geometrical relationship between the vector path of the rounded corner image and each pixel in a bitmap of the rounded corner image, and the color to which each edge pixel should be filled is determined by combining the edge drawing color and the background color of the rounded corner image. The difference among the plurality of edge pixels is only the area proportion covered by the vector path, the colors filled between the adjacent edge pixels in the plurality of edge pixels do not differ greatly, and after the filling color of each edge pixel is adjusted to the corresponding color, the filling color of the edge pixel can be in smooth transition along with the coverage degree of the vector path, so that the coverage degree of the edge pixel is improved. The filling color of the plurality of edge pixels presents a gradual change effect. Namely, the visual effect of a continuous geometric edge is simulated in a discrete pixel grid through fuzzy sawtooth-shaped edge mutation, so that the visual effect better conforms to the perception characteristics of human eyes, and sawtooth-shaped edges are effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of electronic equipment technology, and more specifically, to a method, device, electronic device, and storage medium for processing an image in the field of electronic equipment technology. Background Art

[0002] The user interface of electronic devices often includes images with rounded corners, such as icons with rounded corners and tooltips with rounded corners. Images with rounded corners can improve the aesthetics of applications and user experience.

[0003] Currently, traditional image rendering methods often suffer from aliasing when processing images with rounded corners. This aliasing not only degrades the visual quality of images with rounded corners but also increases the burden on the graphics processor.

[0004] Therefore, how to perform anti-aliasing on rounded corner images is an urgent problem that needs to be solved. Summary of the Invention

[0005] The present application provides a method, device, electronic device and storage medium for processing an image, which can reduce the jagged effect in the process of generating a rounded-corner image.

[0006] In a first aspect, a method for processing an image is provided, the method comprising: in response to a request to render an original image as a rounded-corner image, determining, based on a geometric relationship between a vector path of the rounded-corner image and each pixel in a bitmap of the original image, an area ratio of each edge pixel in the bitmap covered by the vector path, the edge pixel being a pixel in the bitmap that intersects with the vector path; determining, based on the area ratio of each edge pixel covered by the vector path, an edge drawing color of the rounded-corner image, and a background color, a first color that should be filled with each edge pixel; and adjusting the fill color of each edge pixel to the corresponding first color to draw the rounded-corner image.

[0007] In the above technical solution, the geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the rounded corner image is used to determine the area ratio of each edge pixel covered by the vector path. Furthermore, the edge drawing color and background color of the rounded corner image are combined to determine the color that each edge pixel should be filled with. The difference between multiple edge pixels is only the area ratio covered by the vector path. The first color that should be filled between adjacent edge pixels in the multiple edge pixels will not be very different. After adjusting the fill color of each edge pixel to the corresponding first color, the fill color of the edge pixel can be smoothly transitioned with the coverage degree of the vector path, and the fill colors of multiple edge pixels show a gradient effect. That is, by blurring the jagged edge mutations, the visual effect of continuous geometric edges is simulated in a discrete pixel grid, making it more in line with the perception characteristics of the human eye, so as to effectively reduce jagged edges. In addition, this solution concentrates computing resources on key edge areas (edge ​​pixels), which can reduce the processing of unnecessary pixels while maintaining high rendering quality.

[0008] In combination with the first aspect, in some possible implementations, based on the geometric relationship between the vector path of the rounded image and the pixels in the bitmap of the original image, the area ratio of each edge pixel in the bitmap covered by the vector path is determined, including: taking any edge pixel among the N edge pixels in the bitmap corresponding to the rounded corner part of the rounded corner image as a first edge pixel, determining the center of the first rounded corner part corresponding to the first edge pixel in the vector path, where N is a positive integer greater than 2; determining a first distance between the center of the first edge pixel and the center of the circle; determining a first difference between the first distance and the radius of the first rounded corner part, and determining a first area ratio of the first edge pixel covered by the vector path based on the first difference.

[0009] In the above technical solution, by locating the center of the first rounded corner portion corresponding to the first edge pixel, the complex path intersection problem is converted into a spatial coordinate analysis, and the mathematical properties of the vector path (such as the center position, radius, etc.) are used to quickly establish a geometric association. Furthermore, the first distance between the center of the first edge pixel and the center of the circle is determined, and the coverage ratio is derived based on the distance difference between the first distance and the radius of the first rounded corner portion (i.e., the first difference). That is, the mixing weight used to define the color of the first edge pixel is dynamically determined through a nonlinear interpolation model (i.e., a functional relationship between the distance difference and the pixel coverage area). Compared with traditional supersampling technology, the above solution can ensure the smoothness of the color transition of the edge pixels. In addition, the distance difference can also be used to quickly verify the pixels that are completely inside / outside the rounded corner image, reducing the invalid calculation of the color of some pixels and reducing the complexity of calculating the area ratio. Therefore, the above solution can significantly optimize the performance of determining the area ratio of edge pixels covered by the vector path while ensuring visual smoothness.

[0010] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, based on the first difference, determining the first area ratio of the first edge pixel covered by the vector path includes: determining the difference between a first preset value and the absolute value of the first difference as a first ratio, where the first preset value is used to indicate the width of a pixel; and determining the larger value between the first ratio and the first preset ratio as the first area ratio.

[0011] In the above technical solution, the first preset value defined by the width of the pixel is used, and the initial ratio is calculated based on the absolute difference between the first preset value and the distance difference. The size of the pixel is incorporated into the coverage model, which ensures that the area ratio of the edge pixels covered by the vector path is distributed within a reasonable range. Furthermore, by comparing the initial ratio with the preset minimum area ratio (first ratio), and taking the larger value. The above solution forces the area ratio to be no less than the preset lower limit, which can avoid the problem of the area ratio being too small or returning to zero due to a sudden change in the distance difference, thereby maintaining the continuity of the edge pixel transition in color. In addition, the introduction of the preset first ratio can reduce the dependence on complex interpolation functions, so that it can still quickly output smooth edges in low-performance devices. Therefore, the above solution can optimize the stability of the coverage area ratio of edge pixels and the anti-aliasing effect.

[0012] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, based on the geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image, the area ratio of each edge pixel in the bitmap covered by the vector path is determined, including: when there is a straight line portion in the rounded corner image, any straight line portion is used as a first straight line portion, and any edge pixel among the N edge pixels corresponding to the first straight line portion is used as a second edge pixel, and the vertical distance from the center of the second edge pixel to the first straight line portion is determined; based on the vertical distance, a second area ratio of the second edge pixel covered by the vector path is determined.

[0013] In the above technical solution, for any second edge pixel corresponding to the straight line portion in the bitmap, the solution determines the area ratio based on the shortest vertical distance from the center of the second edge pixel to the straight line portion. This can convert the vector parameters of the straight line portion into geometric metrics, and dynamically determine the mixing weight used to define the color of the second edge pixel in combination with the mapping function relationship between the preset vertical distance and the area ratio, so that the sub-pixel rendering of the straight line edge has a smooth transition logic consistent with the rounded corner portion. This solution can avoid discrete sampling of the straight line portion and directly adopt vector parameters to achieve efficient estimation of the area ratio, which can significantly reduce the computational redundancy when determining the second area ratio. In addition, the above vertical distance determination process is suitable for straight line portions of any angle, and there is no need to design special processing logic for different slopes, which can enhance the robustness of the algorithm.

[0014] In combination with the first aspect and the above-mentioned implementation methods, in certain possible implementation methods, determining the first color that each edge pixel should be filled with is based on the area ratio of each edge pixel covered by the vector path, the edge drawing color of the rounded image, and the background color, including: taking any edge pixel among the N edge pixels as a third edge pixel, determining the proportional difference between a second preset ratio and a third area ratio of the third edge pixel covered by the vector path; and based on the third area ratio and the proportional difference, fusing the edge drawing color and the background color to determine the first color that the third edge pixel should be filled with.

[0015] In the above technical solution, based on the area ratio of edge pixels covered by the vector path, a second preset ratio is introduced to construct a proportional difference, and then, the linear interpolation function is combined to dynamically balance the mixing intensity of the edge drawing color and the background color. This allows the proportional difference to approach zero when the area ratio is close to the second preset ratio, and the mixed color tends to be smooth and gradual, which can effectively eliminate the abrupt edge faults. When the area ratio deviates from the second preset ratio, the proportional difference increases, and the mixing weight quickly converges to the background color, reducing the computational redundancy of the intermediate color. This solution can reduce the computational complexity of the color mixing process by constraining the proportional difference while ensuring a smooth transition at the sub-pixel level. Therefore, this solution can significantly improve the efficiency of color mixing while maintaining the anti-aliasing effect, and is particularly suitable for complex scenes with multiple edge colors superimposed or dynamic background changes, ensuring a balance between real-time rendering performance and visual authenticity.

[0016] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the method further includes: for a first type of pixel in the bitmap that has no intersection with the vector path and is located inside the vector path, adjusting the fill color of the first type of pixel to the edge drawing color; for a second type of pixel in the bitmap that has no intersection with the vector path and is located outside the vector path, adjusting the fill color of the second type of pixel to the background color.

[0017] In this technical solution, by clearly dividing the pixels in the bitmap into a first category (those completely covered by the vector path) and a second category (those completely uncovered by the vector path), a preset color is directly applied for filling. This avoids redundant calculations for non-edge pixels. First-category pixels within the vector path are directly filled with the edge drawing color, ensuring consistent color within the internal area and no blending errors. Second-category pixels outside the vector path are uniformly replaced with the background color, eliminating interference from irrelevant pixels. This solution quickly skips the process of determining the area ratio of some pixels based on their geometric position, focusing the computational complexity of the rendering process on the true edge areas, thereby reducing the overall computational load. Furthermore, this rigid shading rule avoids color overflow or translucency artifacts caused by blending calculations, ensuring color purity in non-edge areas. This process complements the anti-aliasing processing of edge pixels, forming a complete rendering pipeline that maintains edge smoothness while efficiently filling large image areas.

[0018] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the method also includes: scaling the bitmap to obtain a first bitmap of a target size; adjusting the fill color of each pixel in the first bitmap to obtain a second bitmap; and determining the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded image and each pixel in the bitmap of the original image, including: determining the area ratio of each edge pixel in the second bitmap covered by the vector path based on the geometric relationship between the vector path and each pixel in the second bitmap.

[0019] In the above technical solution, the original bitmap (i.e., the bitmap) is scaled to generate a first bitmap of the target size. By pre-adjusting the color of each pixel in the first bitmap, the color distribution within the pixel can be preliminarily optimized to obtain the second bitmap. Subsequently, the area ratio is re-determined based on the geometric relationship between the vector path and the pixel on the basis of the second bitmap. The above-mentioned phased processing strategy decouples anti-aliasing processing from resolution adaptation, which can reduce the amount of data for pixel-level operations at high resolution during the scaling phase and reduce the pressure of real-time rendering. In the post-processing stage, the precision loss that may be introduced by scaling is compensated by secondary color adjustment (i.e., the first color process and the second color process). While retaining the mathematical precision of the vector path, this solution can also avoid performing complex geometric calculations directly on the high-resolution bitmap. In addition, the pre-adjustment of the color of the first bitmap can suppress the mosaic effect caused by scaling, ensuring that the final anti-aliasing effect is consistent with the visual performance at the target resolution.

[0020] In combination with the first aspect and the above-mentioned implementation methods, in some possible implementation methods, the fill color of each pixel in the first bitmap is adjusted to obtain a second bitmap, including: taking any pixel in the first bitmap as a fourth pixel, and determining the original pixel coordinates that the fourth pixel should have in the bitmap before scaling the bitmap based on the pixel coordinates of the fourth pixel, the target size, and the size of the bitmap; determining at least four pixels from the bitmap that match the original pixel coordinates; determining a second color that the fourth pixel should be filled with based on the fill colors of the at least four pixels; and adjusting the fill color of the fourth pixel to the second color to obtain the second bitmap.

[0021] In the above technical solution, the original pixel coordinates of each pixel after scaling are reversed and at least four adjacent pixels are extracted through the coordinate mapping relationship between the original bitmap and the target size. The fill colors of at least four pixels are mixed by bilinear interpolation to generate the second color that the fourth pixel should be filled with. This solution retains the local color gradient information in the original bitmap, can suppress the mosaic effect caused by scaling, and especially avoid pixel block distortion when scaling at high magnifications. At the same time, the reverse coordinate mapping can ensure that the scaled bitmap is geometrically aligned with the vector path. In addition, this solution selects at least four pixels, which can avoid performance fluctuations caused by adaptive sampling and make the computational complexity of the scaling stage controllable.

[0022] In a second aspect, a device for processing an image is provided, which includes: a determination module, used to: in response to a request to render an original image as a rounded corner image, determine the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image, where the edge pixel is a pixel in the bitmap that intersects with the vector path; based on the area ratio of each edge pixel covered by the vector path, the edge drawing color of the rounded corner image and the background color, determine the first color that each edge pixel should be filled with; and an adjustment module, used to adjust the fill color of each edge pixel to the corresponding first color to draw the rounded corner image.

[0023] In combination with the second aspect, in some possible implementations, the determination module is specifically used to: take any edge pixel among the N edge pixels in the bitmap corresponding to the rounded corner portion of the rounded corner image as a first edge pixel, determine the center of the first rounded corner portion corresponding to the first edge pixel in the vector path, where N is a positive integer greater than 2; determine a first distance between the center of the first edge pixel and the center of the circle; determine a first difference between the first distance and the radius of the first rounded corner portion, and based on the first difference, determine a first area ratio of the first edge pixel covered by the vector path.

[0024] In combination with the second aspect and the above-mentioned implementation method, in some possible implementation methods, the determination module is further specifically used to: determine the difference between the first preset value and the absolute value of the first difference as a first ratio, where the first preset value is used to indicate the width of a pixel; and determine the larger value between the first ratio and the first preset ratio as the first area ratio.

[0025] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the determination module is further specifically used to: when a straight line portion exists in the rounded-corner image, take any straight line portion as a first straight line portion, and take any edge pixel among the N edge pixels corresponding to the first straight line portion as a second edge pixel, determine the vertical distance from the center of the second edge pixel to the first straight line portion; and based on the vertical distance, determine a second area ratio of the second edge pixel covered by the vector path.

[0026] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the determination module is further specifically used to: take any edge pixel among the N edge pixels as a third edge pixel, determine the proportional difference between the second preset ratio and the third area ratio of the third edge pixel covered by the vector path; based on the third area ratio and the proportional difference, blend the edge drawing color and the background color to determine the first color that should be filled with the third edge pixel.

[0027] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the adjustment module is further used to: for a first type of pixel in the bitmap that has no intersection with the vector path and is located inside the vector path, adjust the fill color of the first type of pixel to the edge drawing color; for a second type of pixel in the bitmap that has no intersection with the vector path and is located outside the vector path, adjust the fill color of the second type of pixel to the background color.

[0028] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the device also includes: a scaling module, which is used to scale the bitmap to obtain a first bitmap of a target size; the adjustment module, which is also used to adjust the fill color of each pixel in the first bitmap to obtain a second bitmap; and the determination module, which is specifically used to determine the area ratio of each edge pixel in the second bitmap covered by the vector path based on the geometric relationship between the vector path and each pixel in the second bitmap.

[0029] In combination with the second aspect and the above-mentioned implementation methods, in some possible implementation methods, the determination module is specifically further used to: take any pixel in the first bitmap as the fourth pixel, and based on the pixel coordinates of the fourth pixel, the target size and the size of the bitmap, determine the original pixel coordinates that the fourth pixel should have in the bitmap before scaling the bitmap; determine at least four pixels from the bitmap that match the original pixel coordinates; based on the fill colors of the at least four pixels, determine the second color that the fourth pixel should be filled with; the adjustment module is specifically further used to adjust the fill color of the fourth pixel to the second color to obtain the second bitmap.

[0030] In a third aspect, an electronic device is provided, comprising a memory and a processor. The memory is configured to store executable program code, and the processor is configured to retrieve and execute the executable program code from the memory, so that the electronic device executes the method of the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 This is a schematic diagram of a scenario for using an electronic device provided in an embodiment of the present application;

[0032] Figure 2 is a schematic flow chart of a method for processing an image provided in an embodiment of the present application;

[0033] Figure 3 is a schematic diagram of a rounded rectangular image provided in an embodiment of the present application;

[0034] Figure 4 This is a schematic diagram of scaling a bitmap provided by an embodiment of the present application;

[0035] Figure 5 is a structural diagram of an image processing device provided in an embodiment of the present application;

[0036] Figure 6 This is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0037] The following will clearly and thoroughly describe the technical solutions in this application in conjunction with the accompanying drawings. In the description of the embodiments of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of this application, "multiple" means two or more than two.

[0038] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.

[0039] Figure 1 This is a schematic diagram of a scenario for using an electronic device provided in an embodiment of the present application.

[0040] For example, Figure 1 As shown, electronic device A processes the original image using a traditional image rendering method to obtain a rounded-corner image. However, traditional image rendering methods produce a jagged effect when processing rounded-corner images. This is because rounded-corner images are composed of many pixel blocks, and resolution is used to measure the number of pixel blocks per unit area. When the resolution is low, the number of pixel blocks per unit area is small, and when the rounded-corner image needs to present some lines, it cannot be very delicate and smooth, and can only be pieced together using a limited number of pixel blocks. This causes the rounded-corner image to have jagged edges. Among them, the jagged effect can not only reduce the visual presentation effect of the rounded-corner image, but may also increase the burden on the graphics processor.

[0041] In related technologies, anti-aliasing processing is usually performed through super sampling anti-aliasing (SSAA) technology, multi sampling anti-aliasing (MSAA) technology, or coverage sampling anti-aliasing (CSAA) technology.

[0042] Among them, the implementation principle of SSAA technology is to enlarge the rounded corner image by several times based on the original resolution, and then reversely sample it back to the original size. For example, a rounded corner image with a resolution of 1024x768 is rendered as a rounded corner image with a resolution of 2048x1536, and then "stuffed" into the image frame of a resolution of 1024x768 to form it. In other words, SSAA technology improves the fineness of the rounded corner image by increasing the sampling rate, thereby improving the jaggedness of the image edge. However, SSAA technology needs to render the image at a high resolution, and the computing resources and memory consumption required will increase significantly. Therefore, the computational overhead of SSAA technology in anti-aliasing processing is very high.

[0043] The MSAA technology only performs anti-aliasing processing on polygonal images. For each edge pixel in the pixel image corresponding to the polygonal image, the color information of multiple pixels surrounding the edge pixel is extracted, and the color information of the multiple pixels is mixed, and the mixed color is used as the final color of the edge pixel. Among them, multiple pixels are determined by a coverage test, which is to test the pixels falling within a frame of a preset shape with the center of the edge pixel as the origin. In other words, the MSAA technology reduces the aliasing effect caused by high-contrast colors by mixing the color information of the pixels surrounding the edge pixel. In addition, under normal circumstances, the edge colors of polygonal images are relatively rich, and the final color of each edge pixel is only determined by the colors of a certain number of pixels around it. From the perspective of the image as a whole, the edge color of the image processed by the MSAA technology may still have a sudden change phenomenon.

[0044] CSAA technology is an improvement on MSAA technology. It uses a preset algorithm to screen multiple pixels around each edge pixel, retain the target pixel with different color information from other pixels, and then mix the color information of the target pixel, and use the mixed color as the final color of the edge pixel. In addition, compared with MSAA technology, CSAA technology can reduce the number of samples of pixels around edge pixels, which can greatly reduce the data processing pressure brought by anti-aliasing processing. Although CSAA technology can reduce the number of samples of pixels around edge pixels, it still needs to determine the multiple pixels around each edge pixel through coverage testing, and the corresponding amount of calculation is not small. In addition, the anti-aliasing effect of CSAA technology needs to be improved.

[0045] In order to better solve the above problems, this application proposes a method for processing images to reduce the jagged effect in the edge area of ​​the rounded image and achieve better anti-aliasing effect. The specific implementation steps can be found in Figure 2 .

[0046] Figure 2 This is a schematic flowchart of a method for processing an image provided in an embodiment of the present application.

[0047] It should be understood that the image processing method provided in the embodiment of the present application can be applied to Figure 1 The electronic device shown (specifically electronic device A).

[0048] For example, Figure 2 As shown, the method 200 includes the following steps 201 to 203.

[0049] Step 201, in response to a request to render an original image as a rounded corner image, determines the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image, where the edge pixel is a pixel in the bitmap that intersects with the vector path.

[0050] It should be understood that the "original image" in the above step 201 refers to an image that has not undergone any rounding processing, and this application does not limit the shape of the original image. Optionally, the shape includes a rectangle, a square, a triangle, etc. Regardless of the shape of the original image, this application will subsequently use a rounded path to achieve a rounded image of the target shape. Correspondingly, the target shape includes a rectangle, a square, a triangle, etc. In other words, the rounded image of the target shape is specifically a rounded rectangular image, a rounded square image, or a rounded triangle image. The target shape is the basic shape of the rounded image.

[0051] It should also be understood that the "bitmap" in the above step 201 refers to presenting the original image in a pixel array, and each pixel in the bitmap is used to record the color of the original image, and the color of each pixel is the color of the corresponding position in the original image. Optionally, the color of each pixel is the color sampling value of the center point of the original image at the corresponding pixel coverage area. In addition, all image operations (including anti-aliasing, scaling, filtering, etc.) need to be completed on the basis of the bitmap. The presentation form of the above original image may be a vector image (such as an SVG image) or a bitmap (such as PNG, JPEG). The essence of the vector image is to describe the original image through mathematical formulas (such as points, lines, curves and polygons, etc.).

[0052] It should be noted that the bitmap of the original image described above is composed of a discrete grid of pixels, each of which can only be filled with a single color. The vector path of the rounded image, however, is a continuous mathematical curve that may pass through multiple pixels in the bitmap. If these multiple pixels are not processed, they may appear to be at least one solid color, resulting in "stair-step" jagged edges on the edges of the rounded image. The present application aims to reduce this jagged effect, specifically through method 200.

[0053] In some embodiments, the method for determining the bitmap of the original image in step 201 includes: when the presentation form of the original image is a vector image, obtaining the original size of the original image; creating a blank third bitmap, and drawing the bitmap of the original image on the third bitmap according to the original size through a canvas tool; when the presentation form of the original image is a bitmap, reusing the bitmap of the original image.

[0054] It should be understood that the above solution can convert the vector image into a bitmap by rasterization, that is, converting the image description method using mathematical formulas into the image description method using pixel arrays.

[0055] 1) When the original image is presented as a bitmap, the bitmap of the original image can be obtained through the following code. if(drawable instanceof BitmapDrawable){

[0056] return((BitmapDrawable)drawable).getBitmap();

[0057] }

[0058] 2) When the original image is presented as a vector image, the following code can be used to obtain the bitmap of the original image.

[0059] drawable.getIntrinsicWidth() / width w in the original size;

[0060] drawable.getIntrinsicHeight() / height h in the original size;

[0061] Bitmap bitmap=Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);

[0062] Canvas canvas=new Canvas(bitmap);

[0063] drawable.setBounds(0,0,w,h);

[0064] drawable.draw(canvas).

[0065] Among them, ARGB_8888 is a configuration (Bitmap.Config) used to define the color storage format of the bitmap, which can determine the storage method of the color information of each pixel in the bitmap.

[0066] The process of "determining the area ratio of each edge pixel in the bitmap covered by the vector path" is described in detail below in two cases.

[0067] Case 1: Edge pixels corresponding to the rounded corners of a rounded image.

[0068] In one possible implementation, step 201 determines the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded image and each pixel in the bitmap of the original image, including: taking any edge pixel among the N edge pixels in the bitmap corresponding to the rounded corner portion of the rounded corner image as a first edge pixel, determining the center of a first rounded corner portion corresponding to the first edge pixel in the vector path, where N is a positive integer greater than 2; determining a first distance between the center of the first edge pixel and the center of the circle; determining a first difference between the first distance and the radius of the first rounded corner portion, and determining a first area ratio of the first edge pixel covered by the vector path based on the first difference.

[0069] It should be understood that the "vector path of the rounded corner image" in the above scheme is composed of multiple edge coordinates of the rounded corner image, and the rounded corner image is ultimately presented in the form of a bitmap. Therefore, it is necessary to determine the geometric relationship between each edge pixel in the N edge pixels and the vector path.

[0070] It should also be understood that the rounded corner image includes a rounded corner portion. For example, when the rounded corner image is a rounded corner rectangular image, it includes four rounded corner portions. Furthermore, some rounded corner images also include a straight line portion. For example, a rounded corner rectangular image also includes four straight line portions. In the above scheme, any edge pixel corresponding to the rounded corner portion of the rounded corner image among the N edge pixels in the bitmap (i.e., the first edge pixel, the first edge pixel belongs to a certain rounded corner portion (e.g., the first rounded corner portion)) is taken as an example to describe the process of determining the area ratio of the first edge pixel covered by the vector path. In the above scheme, the "edge pixel corresponding to the rounded corner portion of the rounded corner image" can be an edge pixel falling on the rounded corner portion, including the edge pixel whose center falls on the rounded corner portion or the edge pixel whose lower left corner falls on the rounded corner portion.

[0071] Optionally, the pixel coordinates of the first edge pixel are (p x , p y ), the pixel coordinates of its center are (p x +0.5, p t +0.5). In the above, the pixel coordinates of edge pixels are referred to as the lower left corner of the pixel.

[0072] In the above technical solution, by locating the center of the first rounded corner portion corresponding to the first edge pixel, the complex path intersection problem is converted into a spatial coordinate analysis, and the mathematical properties of the vector path (such as the center position, radius, etc.) are used to quickly establish a geometric association. Furthermore, the first distance between the center of the first edge pixel and the center of the circle is determined, and the coverage ratio is derived based on the distance difference between the first distance and the radius of the first rounded corner portion (i.e., the first difference). That is, the mixing weight used to define the color of the first edge pixel is dynamically determined through a nonlinear interpolation model (i.e., a functional relationship between the distance difference and the pixel coverage area). Compared with traditional supersampling technology, the above solution can ensure the smoothness of the color transition of the edge pixels. In addition, the distance difference can also be used to quickly verify the pixels that are completely inside / outside the rounded corner image, reducing the invalid calculation of the color of some pixels and reducing the complexity of calculating the area ratio. Therefore, the above solution can significantly optimize the performance of determining the area ratio of edge pixels covered by the vector path while ensuring visual smoothness.

[0073] For example, Figure 3 As shown, a rounded rectangular image is given, in which the four corner portions of the rounded rectangular image are rounded portions, and the rest are straight portions. The upper right rounded corner in the rounded rectangular image is specifically the first rounded portion, and the first rounded portion (a portion of the path in the vector path of the rounded rectangular image) intersects with the first edge pixel. Specifically, the present application determines a first distance based on the pixel coordinates of the center of the first rounded portion and the pixel coordinates of the center of the first edge pixel, and determines a first difference between the first distance and the radius r of the first rounded portion, and based on the first difference, determines a first area ratio of the first edge pixel covered by the vector path.

[0074] In some embodiments, determining a first distance between the center of the first edge pixel and the center of the circle includes: determining the first distance based on the following formula (1);

[0075]

[0076] Wherein, d1 is the first distance, (c x , c y ) is the pixel coordinate of the center of the first rounded corner.

[0077] In some embodiments, determining a first difference between the first distance and the radius of the first rounded portion includes: determining the first difference based on the following formula (2);

[0078] Δ1=d1-r (2)

[0079] Wherein, Δ1 is the first difference, and r is the radius of the first rounded corner portion.

[0080] In one possible implementation, determining a first area ratio of the first edge pixel covered by the vector path based on the first difference includes: determining the difference between a first preset value and the absolute value of the first difference as a first ratio, where the first preset value is used to indicate the width of a pixel; and determining the larger value between the first ratio and the first preset ratio as the first area ratio.

[0081] It should be understood that the "first preset value" in the above scheme is 1, that is, the width of one pixel. In addition, under normal circumstances, the length and width of a pixel are the same, that is, the length of a pixel is 1. In other words, the above scheme determines the first area ratio by the following formula: α1=max(0,1-|Δ1|), where 1-|Δ1| is the first ratio, α1 is the first area ratio, and 0 is the first preset ratio. For any first edge pixel, its corresponding first difference is in When the first difference is 0, it means that the vector path of the rounded image just passes through the center of the first edge pixel. When , it indicates that the vector path of the rounded corner image just passes through the first edge pixel (that is, specifically the lower left corner position of the first edge pixel).

[0082] It should also be understood that the present application can also discuss the geometric relationship between other pixels in the bitmap and the rounded corner image (specifically the first rounded corner portion) through formula (2). When , the pixel is located inside the first rounded corner, that is, the pixel is completely inside the rounded corner image; , the pixel is located outside the first rounded corner, that is, the pixel is completely outside the rounded corner image.

[0083] In the above technical solution, the first preset value defined by the width of the pixel is used, and the initial ratio is calculated based on the absolute difference between the first preset value and the distance difference. The size of the pixel is incorporated into the coverage model, which ensures that the area ratio of the edge pixels covered by the vector path is distributed within a reasonable range. Furthermore, by comparing the initial ratio with the preset minimum area ratio (first ratio), and taking the larger value. The above solution forces the area ratio to be no less than the preset lower limit, which can avoid the problem of the area ratio being too small or returning to zero due to a sudden change in the distance difference, thereby maintaining the continuity of the edge pixel transition in color. In addition, the introduction of the preset first ratio can reduce the dependence on complex interpolation functions, so that it can still quickly output smooth edges in low-performance devices. Therefore, the above solution can optimize the stability of the coverage area ratio of edge pixels and the anti-aliasing effect.

[0084] Case 2: Edge pixels corresponding to the straight line portion of the rounded image.

[0085] In one possible implementation, step 201 determines the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image, including: when there is a straight line portion in the rounded corner image, taking any straight line portion as a first straight line portion, and taking any edge pixel among the N edge pixels corresponding to the first straight line portion as a second edge pixel, determining the vertical distance from the center of the second edge pixel to the first straight line portion; and determining a second area ratio of the second edge pixel covered by the vector path based on the vertical distance.

[0086] It should be understood that the above scheme uses any edge pixel corresponding to a straight line portion of a rounded corner image (i.e., a second edge pixel, which belongs to a straight line portion (e.g., a first straight line portion)) among the N edge pixels in the bitmap as an example to describe the process of determining the area ratio of the second edge pixel covered by the vector path. The N edge pixels include first-category edge pixels corresponding to rounded corner portions (i.e., first edge pixels) and second-category edge pixels corresponding to straight line portions (i.e., second edge pixels).

[0087] In the above technical solution, for any second edge pixel corresponding to the straight line portion in the bitmap, the solution determines the area ratio based on the shortest vertical distance from the center of the second edge pixel to the straight line portion. This can convert the vector parameters of the straight line portion into geometric metrics, and dynamically determine the mixing weight used to define the color of the second edge pixel in combination with the mapping function relationship between the preset vertical distance and the area ratio, so that the sub-pixel rendering of the straight line edge has a smooth transition logic consistent with the rounded corner portion. This solution can avoid discrete sampling of the straight line portion and directly adopt vector parameters to achieve efficient estimation of the area ratio, which can significantly reduce the computational redundancy when determining the second area ratio. In addition, the above vertical distance determination process is suitable for straight line portions of any angle, and there is no need to design special processing logic for different slopes, which can enhance the robustness of the algorithm.

[0088] In some embodiments, determining a vertical distance from the center of the second edge pixel to the first straight line portion includes: determining the vertical distance based on the following formula (3) when the first straight line portion is parallel to the horizontal axis; and determining the vertical distance based on the following formula (4) when the first straight line portion is parallel to the vertical axis.

[0089] Δ2=p y +0.5-y1 (3)

[0090] Δ2=p x +0.5-x1 (4)

[0091] Among them, Δ2 is the vertical distance, p y+0.5 is the vertical axis value in the pixel coordinates of the center of the second edge pixel, y1 is the mathematical expression of the first straight line portion when the first straight line portion is parallel to the horizontal axis, p x +0.5 is the horizontal axis value of the pixel coordinates of the center of the second edge pixel, and x1 is a mathematical expression of the first straight line portion when the first straight line portion is parallel to the vertical axis.

[0092] It should be understood that in the above solution, when the rounded-corner image is a rounded rectangular image and the first straight line portion is parallel to the horizontal axis, the mathematical expression for the first straight line portion is y1 = a1. Here, a1 is an arbitrary value. When the rounded-corner image is a rounded rectangular image and the first straight line portion is parallel to the vertical axis, the mathematical expression for the first straight line portion is x1 = b1. Here, b1 is an arbitrary value.

[0093] It should also be understood that for any second edge pixel, the corresponding vertical distance is in the range [0, 0.5]. When the vertical distance is 0, the vector path representing the rounded corner image just passes through the center of the second edge pixel. When the vertical distance is 0.5, the vector path representing the rounded corner image just passes through the second edge pixel (i.e., specifically, the lower boundary of the second edge pixel).

[0094] In some embodiments, determining a second area ratio of the second edge pixel covered by the vector path based on the vertical distance includes: determining the second area ratio based on the following formula (5);

[0095] α2=max(0,1-|Δ2|) (5)

[0096] Wherein, α2 is the second area ratio.

[0097] Step 202 : determining a first color to be filled with each edge pixel based on the area ratio of each edge pixel covered by the vector path, the edge drawing color of the rounded image, and the background color.

[0098] It should be understood that the "edge drawing color of the rounded corner image" in step 202 is pre-set and can be obtained from the request to render the original image as a rounded corner image. Optionally, the edge drawing color is green. Typically, the edge drawing color of the rounded corner image is a certain color.

[0099] It should also be understood that the "background color of the rounded-corner image" in step 202 above refers to the bottom-most color of the rounded-corner image, which serves to highlight other elements in the rounded-corner image. The background color of the rounded-corner image is a specific color. Optionally, if the rounded-corner image is a landscape image with a sky background, the background color of the rounded-corner image is blue.

[0100] It should be noted that the difference between multiple edge pixels lies in the proportion of the area covered by the vector path. After determining the first color that each edge pixel should be filled with based on the proportion of the area covered by the vector path, the edge drawing color and the background color, the first colors that should be filled between adjacent edge pixels among the multiple edge pixels will not differ greatly, and the first colors that the multiple edge pixels should be filled with will present a gradient effect.

[0101] In one possible implementation, step 202 includes: taking any edge pixel among the N edge pixels as a third edge pixel, determining a proportional difference between a second preset ratio and a third area ratio of the third edge pixel covered by the vector path; and based on the third area ratio and the proportional difference, blending the edge drawing color and the background color to determine a first color that should be filled with the third edge pixel.

[0102] It should be understood that the “second preset ratio” in the above solution is 1.

[0103] In the above technical solution, based on the area ratio of edge pixels covered by the vector path, a second preset ratio is introduced to construct a proportional difference, and then, the linear interpolation function is combined to dynamically balance the mixing intensity of the edge drawing color and the background color. This allows the proportional difference to approach zero when the area ratio is close to the second preset ratio, and the mixed color tends to be smooth and gradual, which can effectively eliminate the abrupt edge faults. When the area ratio deviates from the second preset ratio, the proportional difference increases, and the mixing weight quickly converges to the background color, reducing the computational redundancy of the intermediate color. This solution can reduce the computational complexity of the color mixing process by constraining the proportional difference while ensuring a smooth transition at the sub-pixel level. Therefore, this solution can significantly improve the efficiency of color mixing while maintaining the anti-aliasing effect, and is particularly suitable for complex scenes with multiple edge colors superimposed or dynamic background changes, ensuring a balance between real-time rendering performance and visual authenticity.

[0104] In some embodiments, based on the third area ratio and the ratio difference, the edge drawing color and the background color are merged to determine the first color that the third edge pixel should be filled with, including: determining the first color that the third edge pixel should be filled with based on the following formula (6);

[0105] colour1=α3*c draw +α diff *c bgd (6)

[0106] Among them, colour1 is the first color that the third edge pixel should be filled with, α3 is the third area ratio, c draw The edge drawing color, α diff is the ratio difference, c bgdFor the background color.

[0107] Step 203: Adjust the filling color of each edge pixel to the corresponding first color to draw the rounded corner image.

[0108] It should be understood that the "fill color of each edge pixel" in step 203 is the original fill color of each edge pixel in the bitmap. Based on the explanation of step 201, the original fill color of each edge pixel in the bitmap causes the edges of the rounded image to appear "stair-step" jagged.

[0109] It should be noted that, compared to the aforementioned SSAA technique, this method 200 only uses vector paths to determine the edge pixels and the area ratio corresponding to each edge pixel. For any edge pixel, the final fill color of the edge pixel is determined using formula (6). This method 200 does not require rendering the image at a high resolution and requires only a small amount of computation. Compared to the aforementioned MSAA technique and CSAA technique, this method 200 does not require determining the multiple pixels surrounding each edge pixel through a coverage test, but instead determines the area ratio corresponding to each edge pixel. Since the area ratios of the multiple edge pixels in the bitmap covered by the vector path are smoothly transitioned, and the difference between the multiple edge pixels is only in the area ratio covered by the vector path, the colors to be filled between adjacent edge pixels in the multiple edge pixels will not differ significantly. After adjusting the fill color of each edge pixel to the corresponding first color, the fill colors of the multiple edge pixels strictly present a gradient effect, that is, there is no sudden change in the edge color. Therefore, compared to related technologies, this method can achieve a better anti-aliasing effect.

[0110] In one possible implementation, after step 203, the method 200 further includes: for a first type of pixel in the bitmap that has no intersection with the vector path and is located inside the vector path, adjusting the fill color of the first type of pixel to the edge drawing color; for a second type of pixel in the bitmap that has no intersection with the vector path and is located outside the vector path, adjusting the fill color of the second type of pixel to the background color.

[0111] It should be understood that in the above solution, the fill colors of pixels other than edge pixels are determined. The first type of pixels mentioned above can be regarded as pixels completely located within the rounded image, and the second type of pixels can be regarded as pixels completely located outside the rounded image.

[0112] In this technical solution, by clearly dividing the pixels in the bitmap into a first category (those completely covered by the vector path) and a second category (those completely uncovered by the vector path), a preset color is directly applied for filling. This avoids redundant calculations for non-edge pixels. First-category pixels within the vector path are directly filled with the edge drawing color, ensuring consistent color within the internal area and no blending errors. Second-category pixels outside the vector path are uniformly replaced with the background color, eliminating interference from irrelevant pixels. This solution quickly skips the process of determining the area ratio of some pixels based on their geometric position, focusing the computational complexity of the rendering process on the true edge areas, thereby reducing the overall computational load. Furthermore, this rigid shading rule avoids color overflow or translucency artifacts caused by blending calculations, ensuring color purity in non-edge areas. This process complements the anti-aliasing processing of edge pixels, forming a complete rendering pipeline that maintains edge smoothness while efficiently filling large image areas.

[0113] In some embodiments, after step 203, the method 200 further includes: for first-type pixels in the bitmap that have no intersection with the vector path and are located inside the vector path, adjusting the fill color of the first-type pixels to the edge drawing color; and cropping the image area outside the N edge pixels in the bitmap to obtain a cropped rounded image.

[0114] It should be understood that the “image area outside the N edge pixels” in the above solution refers to the image area in the bitmap that has no intersection with the vector path and is located outside the vector path.

[0115] It should be noted that in some scenarios, there is a need to generate a rounded image of the target size. Therefore, this application also needs to scale the bitmap of the original image. The following introduces the process of "scaling the bitmap, and determining the area ratio of each edge pixel in the scaled bitmap covered by the vector path".

[0116] In one possible implementation, after step 201, the method 200 further includes: scaling the bitmap to obtain a first bitmap of a target size; adjusting the fill color of each pixel in the first bitmap to obtain a second bitmap; and, in step 202, determining the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded image and each pixel in the bitmap of the original image, including: determining the area ratio of each edge pixel in the second bitmap covered by the vector path based on the geometric relationship between the vector path and each pixel in the second bitmap.

[0117] It should be understood that in the above solution, after the bitmap is scaled, since the newly added pixels have no data support from the original image, the fill color of the newly added pixels must be determined by an interpolation algorithm. If the interpolation algorithm is too simple, a mosaic effect will occur at the newly added pixels. For example, Figure 4 As shown in (a), after enlarging the heart shape, we get Figure 4 The heart shape in (b) has a mosaic effect.

[0118] In the above technical solution, the original bitmap (i.e., the bitmap) is scaled to generate a first bitmap of the target size. By pre-adjusting the color of each pixel in the first bitmap, the color distribution within the pixel can be preliminarily optimized to obtain the second bitmap. Subsequently, the area ratio is re-determined based on the geometric relationship between the vector path and the pixel on the basis of the second bitmap. The above-mentioned phased processing strategy decouples anti-aliasing processing from resolution adaptation, which can reduce the amount of data for pixel-level operations at high resolution during the scaling phase and reduce the pressure of real-time rendering. In the post-processing stage, the precision loss that may be introduced by scaling is compensated by secondary color adjustment (i.e., the first color process and the second color process). While retaining the mathematical precision of the vector path, this solution can also avoid performing complex geometric calculations directly on the high-resolution bitmap. In addition, the pre-adjustment of the color of the first bitmap can suppress the mosaic effect caused by scaling, ensuring that the final anti-aliasing effect is consistent with the visual performance at the target resolution.

[0119] In some embodiments, the bitmap can be scaled using the following code to obtain a first bitmap of a target size.

[0120] BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); / / Bind the bitmap to the BitmapShader shader and set the tiling mode to edge stretch CLAMP.

[0121] float scale = max(width in target size / width of bitmap, height in target size / height of bitmap);

[0122] matrix.setScale(scale,scale); / Use the matrix tool to determine the scaling ratio and ensure that the scaled bitmap fills the first bitmap of the target size;

[0123] shader.setLocalMatrix(matrix).

[0124] In one possible implementation, the fill color of each pixel in the first bitmap is adjusted to obtain the second bitmap, including: taking any pixel in the first bitmap as a fourth pixel, and determining the original pixel coordinates of the fourth pixel in the bitmap before scaling the bitmap based on the pixel coordinates of the fourth pixel, the target size, and the size of the bitmap; determining at least four pixels from the bitmap that match the original pixel coordinates; determining a second color that the fourth pixel should be filled with based on the fill colors of the at least four pixels; and adjusting the fill color of the fourth pixel to the second color to obtain the second bitmap.

[0125] It should be understood that the horizontal and vertical axis values ​​in the "original pixel coordinates" in the above scheme are usually floating point numbers. In addition, the above scheme can be regarded as performing bilinear interpolation on the pixels in the scaled bitmap through a bilinear filtering algorithm to avoid mosaic effects.

[0126] In the above technical solution, the original pixel coordinates of each pixel after scaling are reversed and at least four adjacent pixels are extracted through the coordinate mapping relationship between the original bitmap and the target size. The fill colors of at least four pixels are mixed by bilinear interpolation to generate the second color that the fourth pixel should be filled with. This solution retains the local color gradient information in the original bitmap, can suppress the mosaic effect caused by scaling, and especially avoid pixel block distortion when scaling at high magnifications. At the same time, the reverse coordinate mapping can ensure that the scaled bitmap is geometrically aligned with the vector path. In addition, this solution selects at least four pixels, which can avoid performance fluctuations caused by adaptive sampling and make the computational complexity of the scaling stage controllable.

[0127] In some embodiments, determining, based on the pixel coordinates of the fourth pixel, the target size, and the size of the bitmap, the original pixel coordinates of the fourth pixel in the bitmap before scaling the bitmap includes: determining the original pixel coordinates based on the following formula (7);

[0128]

[0129] Among them, (x original ,y original ) is the original pixel coordinate, (x new ,y new ) is the pixel coordinate of the fourth pixel, w o The width of the bitmap, w n is the width of the target size, h o The height of the bitmap, h n The height of the target size.

[0130] In some embodiments, determining at least four pixels that match the original pixel coordinates from the bitmap includes: determining a first horizontal axis value and a second horizontal axis value based on the horizontal axis value in the original pixel coordinates, the first horizontal axis value being an integer less than the horizontal axis value, and the second horizontal axis value being an integer greater than the horizontal axis value; determining a first vertical axis value and a second vertical axis value based on the vertical axis value in the original pixel coordinates, the first vertical axis value being an integer less than the vertical axis value, and the second vertical axis value being an integer greater than the vertical axis value; determining the at least four pixels based on the first horizontal axis value, the second horizontal axis value, the first vertical axis value, and the second vertical axis value.

[0131] In some embodiments, determining the at least four pixels based on the first horizontal axis value, the second horizontal axis value, the first vertical axis value, and the second vertical axis value includes: determining the at least four pixels based on the following formula (8);

[0132]

[0133] The at least four pixels include a first pixel, a second pixel, a third pixel, and a fourth pixel, and x 1h is the first horizontal axis value, x 2h is the second horizontal axis value, y 1l is the first vertical axis value, y 2l is the second vertical axis value.

[0134] In some embodiments, based on the fill colors of the at least four pixels, determining the second color that the fourth pixel should be filled with includes: determining the first color value based on the fill color of the first pixel among the at least four pixels, the fill color of the second pixel and the horizontal axis value in the original pixel coordinates; determining the second color value based on the fill color of the third pixel among the at least four pixels, the fill color of the fourth pixel and the horizontal axis value in the original pixel coordinates; determining the second color based on the first color value, the second color value and the vertical axis value in the original pixel coordinates.

[0135] In some embodiments, determining a first color value based on a fill color of a first pixel in the at least four pixels, a fill color of a second pixel, and a horizontal axis value in the original pixel coordinates includes: determining the first color value based on the following formula (9) and formula (10);

[0136] colour 11 =C1*(1-dx)+C2*dx (9)

[0137]

[0138] Among them, color 11 is the first color value.

[0139] In some embodiments, determining a second color value based on a fill color of a third pixel in the at least four pixels, a fill color of a fourth pixel, and a horizontal axis value in the original pixel coordinates includes: determining the second color value based on the following formula (11);

[0140] colour 22 =C3*(1-dx)+C4*dx (11)

[0141] Among them, color 22 is the second color value.

[0142] In some embodiments, determining the second color based on the first color value, the second color value, and the vertical axis value in the original pixel coordinates includes: determining the second color based on the following formula (12) and formula (13);

[0143] Colour2=Colour 11 …(1-dy)+colour 22 *dy (12)

[0144]

[0145] Wherein, colour2 is the second color.

[0146] Exemplarily, the process of determining the second color is described by taking the pixel coordinates of the fourth pixel as (3, 5), the target size as 200*200, and the size of the bitmap as 100*100 as an example.

[0147] Specifically, based on formula (7), the original pixel coordinates are determined to be (1.5, 2.5), and based on formula (8), the pixel coordinates of at least four pixels are determined to be C1(1, 2), C2(2, 2), C3(1, 3), and C4(2, 3). It is known that the color values ​​of the four pixels at the above pixel coordinates are C1(1, 2): (255, 0, 0), C2(2, 2): (0, 255, 0), C3(1, 3): (0, 0, 255), and C4(2, 3): (255, 255, 255).

[0148] Specifically, based on formula (9) and formula (10), the first color value is determined to be (255, 0, 0)*(1-0.5)+(0, 255, 0)*0.5=(127, 127, 0); based on formula (11), the second color value is determined to be (0, 0, 255)*(1-0.5)+(255, 255, 255)*0.5=(127, 127, 255), where 0.5 is dx; based on formula (12) and formula (13), the second color is determined to be (127, 127, 0)*(1-0.5)+(127, 127, 255)*0.5=(127, 127, 127), where 0.5 is dy, that is, the second color is gray.

[0149] In some embodiments, a rounded corner image may be drawn using the following code.

[0150] Paint paint = new Paint();

[0151] paint.setShader(shader);

[0152] paint.setFilterBitmap(true); / / Start the bilinear filtering algorithm mentioned above

[0153] paint.setAntiAlias(true); / / Start smooth edge jaggedness, corresponding to steps 201 to 202

[0154] canvas.drawRoundRect(rectF,radius,radius,paint). / / corresponds to step 203

[0155] Figure 5 It is a structural diagram of a device for processing images provided in an embodiment of the present application.

[0156] For example, Figure 5 As shown, the device 500 includes:

[0157] The determination module 501 is configured to:

[0158] In response to a request to render an original image as a rounded-corner image, determining, based on a geometric relationship between a vector path of the rounded-corner image and each pixel in a bitmap of the original image, an area ratio of each edge pixel in the bitmap that is covered by the vector path, where the edge pixel is a pixel in the bitmap that intersects with the vector path; and determining, based on the area ratio of each edge pixel covered by the vector path, an edge drawing color of the rounded-corner image, and a background color, a first color that should be filled in each edge pixel.

[0159] The adjustment module 502 is configured to adjust the filling color of each edge pixel to a corresponding first color to draw the rounded image.

[0160] Optionally, the determination module 501 is specifically used to: take any edge pixel among the N edge pixels in the bitmap corresponding to the rounded corner portion of the rounded corner image as a first edge pixel, determine the center of a first rounded corner portion corresponding to the first edge pixel in the vector path, where N is a positive integer greater than 2; determine a first distance between the center of the first edge pixel and the center of the circle; determine a first difference between the first distance and the radius of the first rounded corner portion, and based on the first difference, determine a first area ratio of the first edge pixel covered by the vector path.

[0161] Optionally, the determination module 501 is further specifically used to: determine the difference between the first preset value and the absolute value of the first difference as a first ratio, where the first preset value is used to indicate the width of a pixel; and determine the larger value between the first ratio and the first preset ratio as the first area ratio.

[0162] Optionally, the determination module 501 is further specifically configured to: when there is a straight line portion in the rounded corner image, take any straight line portion as a first straight line portion, and take any edge pixel among the N edge pixels corresponding to the first straight line portion as a second edge pixel, determine a vertical distance from the center of the second edge pixel to the first straight line portion; and determine a second area ratio of the second edge pixel covered by the vector path based on the vertical distance.

[0163] Optionally, the determination module 501 is further specifically used to: take any edge pixel among the N edge pixels as a third edge pixel, determine the proportional difference between the second preset ratio and the third area ratio of the third edge pixel covered by the vector path; based on the third area ratio and the proportional difference, merge the edge drawing color and the background color to determine the first color that the third edge pixel should be filled with.

[0164] Optionally, the adjustment module 502 is further used to: for a first type of pixel in the bitmap that has no intersection with the vector path and is located inside the vector path, adjust the fill color of the first type of pixel to the edge drawing color; for a second type of pixel in the bitmap that has no intersection with the vector path and is located outside the vector path, adjust the fill color of the second type of pixel to the background color.

[0165] Optionally, the device 500 also includes: a scaling module, used to scale the bitmap to obtain a first bitmap of a target size; the adjustment module 502, further used to adjust the fill color of each pixel in the first bitmap to obtain a second bitmap; and the determination module 501, specifically further used to determine the area ratio of each edge pixel in the second bitmap covered by the vector path based on the geometric relationship between the vector path and each pixel in the second bitmap.

[0166] Optionally, the determination module 501 is further specifically used to: take any pixel in the first bitmap as the fourth pixel, and determine the original pixel coordinates of the fourth pixel in the bitmap before scaling the bitmap based on the pixel coordinates of the fourth pixel, the target size and the size of the bitmap; determine at least four pixels from the bitmap that match the original pixel coordinates; and determine the second color that the fourth pixel should be filled with based on the fill colors of the at least four pixels; the adjustment module 502 is further specifically used to adjust the fill color of the fourth pixel to the second color to obtain the second bitmap.

[0167] Figure 6 This is a structural diagram of an electronic device provided in an embodiment of the present application.

[0168] For example, Figure 6 As shown, the electronic device 600 includes: a memory 601 and a processor 602, wherein the memory 601 stores an executable program code 603, and the processor 602 is used to call and execute the executable program code 603 to perform a method for processing an image.

[0169] In addition, an embodiment of the present application also protects a device, which may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to perform a method for processing an image provided by an embodiment of the present application.

[0170] In this embodiment, the device can be divided into functional modules based on the above-described method examples. For example, each functional module can be mapped to a specific functional module, or two or more functions can be integrated into a single processing module. The integrated module can be implemented in hardware. It should be noted that the module division in this embodiment is illustrative and represents only a logical functional division. In actual implementation, other division methods may be used.

[0171] In the case of dividing the functional modules into corresponding modules, the device may further include a determination module, an adjustment module, a scaling module, etc. It should be noted that all relevant contents involved in the above method embodiments can be referred to the functional description of the corresponding functional modules and will not be repeated here.

[0172] It should be understood that the device provided in this embodiment is used to execute the above-mentioned method for processing an image, and thus can achieve the same effect as the above-mentioned implementation method.

[0173] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is applied to an electronic device, the processing module may be used to control and manage the operation of the electronic device. The storage module may be used to support the electronic device in executing relevant executable program code.

[0174] The processing module may be a processor or controller that implements or executes the various exemplary logic blocks, modules, and circuits described in conjunction with the present disclosure. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processing (DSP) and a microprocessor, and the storage module may be a memory.

[0175] In addition, the device provided in the embodiments of the present application can specifically be a chip, component or module, and the chip may include a connected processor and memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a method for processing an image provided in the above embodiment.

[0176] This embodiment also provides a computer-readable storage medium, which stores computer program code. When the computer program code runs on a computer, the computer executes the above-mentioned related method steps to implement a method for processing an image provided by the above embodiment.

[0177] This embodiment further provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the above-mentioned related steps to implement the method for processing an image provided by the above embodiment.

[0178] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0179] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0180] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0181] The above content is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A method for processing an image, characterized in that: The method comprises: In response to a request to render an original image as a rounded-corner image, determining, based on a geometric relationship between a vector path of the rounded-corner image and each pixel in a bitmap of the original image, an area ratio of each edge pixel in the bitmap that is covered by the vector path, wherein the edge pixel is a pixel in the bitmap that intersects with the vector path; Determining a first color that should be filled with each edge pixel based on an area ratio of each edge pixel covered by the vector path, an edge drawing color of the rounded image, and a background color; The filling color of each of the edge pixels is adjusted to the corresponding first color to draw the rounded corner image.

2. The method according to claim 1, characterized in that The determining, based on a geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image, an area ratio of each edge pixel in the bitmap covered by the vector path includes: Taking any edge pixel corresponding to the rounded corner portion of the rounded corner image among the N edge pixels in the bitmap as a first edge pixel, and determining the center of a first rounded corner portion corresponding to the first edge pixel in the vector path, where N is a positive integer greater than 2; determining a first distance between a center of the first edge pixel and a center of the circle; A first difference between the first distance and a radius of the first rounded portion is determined, and based on the first difference, a first area ratio of the first edge pixel covered by the vector path is determined.

3. The method according to claim 2, characterized in that Determining a first area ratio of the first edge pixel covered by the vector path based on the first difference includes: determining a difference between a first preset value and an absolute value of the first difference as a first ratio, wherein the first preset value is used to indicate a width of one pixel; The larger value between the first ratio and the first preset ratio is determined as the first area ratio.

4. The method according to claim 1, wherein The determining, based on a geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image, an area ratio of each edge pixel in the bitmap covered by the vector path includes: When there is a straight line portion in the rounded corner image, any straight line portion is used as a first straight line portion, and any edge pixel corresponding to the first straight line portion among the N edge pixels is used as a second edge pixel, and a vertical distance from a center of the second edge pixel to the first straight line portion is determined; Based on the vertical distance, a second area ratio of the second edge pixel covered by the vector path is determined.

5. The method according to claim 1, wherein The determining, based on the area ratio of each edge pixel covered by the vector path, the edge drawing color of the rounded image, and the background color, of the first color that each edge pixel should be filled with includes: Taking any edge pixel among the N edge pixels as a third edge pixel, and determining a ratio difference between a second preset ratio and a third area ratio of the third edge pixel covered by the vector path; Based on the third area ratio and the ratio difference, the edge drawing color and the background color are merged to determine a first color that the third edge pixel should be filled with.

6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: For first-type pixels in the bitmap that have no intersection with the vector path and are located inside the vector path, adjusting the fill color of the first-type pixels to the edge drawing color; For the second type of pixels in the bitmap that have no intersection with the vector path and are located outside the vector path, the filling color of the second type of pixels is adjusted to the background color.

7. The method according to any one of claims 1 to 5, characterized in that The method further comprises: Scaling the bitmap to obtain a first bitmap of a target size; Adjusting the fill color of each pixel in the first bitmap to obtain a second bitmap; Furthermore, determining the area ratio of each edge pixel in the bitmap covered by the vector path based on the geometric relationship between the vector path of the rounded corner image and each pixel in the bitmap of the original image includes: Based on a geometric relationship between the vector path and each pixel in the second bitmap, an area ratio of each edge pixel in the second bitmap covered by the vector path is determined.

8. The method according to claim 7, characterized in that The step of adjusting the fill color of each pixel in the first bitmap to obtain the second bitmap includes: Taking any pixel in the first bitmap as a fourth pixel, and determining, based on the pixel coordinates of the fourth pixel, the target size, and the size of the bitmap, the original pixel coordinates of the fourth pixel in the bitmap before scaling the bitmap; determining at least four pixels from the bitmap that match the original pixel coordinates; Determining a second color that the fourth pixel should be filled with based on the filling colors of the at least four pixels; The filling color of the fourth pixel is adjusted to the second color to obtain the second bitmap.

9. A device for processing an image, characterized in that: The device comprises: Identify modules for: In response to a request to render an original image as a rounded-corner image, determining, based on a geometric relationship between a vector path of the rounded-corner image and each pixel in a bitmap of the original image, an area ratio of each edge pixel in the bitmap that is covered by the vector path, wherein the edge pixel is a pixel in the bitmap that intersects with the vector path; Determining a first color that should be filled with each edge pixel based on an area ratio of each edge pixel covered by the vector path, an edge drawing color of the rounded image, and a background color; The adjustment module is used to adjust the filling color of each edge pixel to the corresponding first color to draw the rounded corner image.

10. An electronic device, characterized in that: The electronic device comprises: a memory for storing executable program code; A processor is configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 8.