Disclosure of Invention
In order to solve the problem that the influence of the target base map on the drawn characters is not considered in the related art, which may cause a certain difference between the color of the characters drawn in the target base map and the expected color, embodiments of the present invention provide a character drawing method and apparatus, a terminal, and a storage medium. The technical scheme is as follows:
in a first aspect, a method for drawing a text is provided, including:
the method comprises the steps that a preset color value of each pixel point of a character to be drawn is adopted, the character to be drawn is drawn on a temporary base map, each character consists of a plurality of pixel points, the color value comprises a transparency component and a plurality of color components, the transparency component and the color component of all the pixel points in the temporary base map are both 0, and the character to be drawn is a character to be drawn on a target base map;
comparing whether the color component of a first pixel point on the temporary base map is different from the pre-configured color component of a corresponding pixel point of the character to be drawn, wherein the first pixel point is any pixel point drawn on the temporary base map;
if the color component of a first pixel point on the temporary base map is different from the color component configured in advance of a corresponding pixel point of the character to be drawn, determining a target color value of a second pixel point, wherein the target color value is obtained based on the color component of the first pixel point and the transparency of the target base map, and the second pixel point is the pixel point of the character to be drawn corresponding to the first pixel point;
and drawing a second pixel point on the target base map by adopting the target color value.
Optionally, the contrast between the target color value and the target base map is smaller than the contrast between the color value of the first pixel point and the target base map.
Optionally, the target color values comprise: determining a target color value of the second pixel point includes:
acquiring a transparency component of the target base map;
acquiring a transparency component of the first pixel point, wherein the transparency component of the first pixel point is determined according to the color component of the first pixel point;
and determining the target transparency component according to the transparency component of the target base map and the transparency component of the first pixel point.
Optionally, the target color values comprise: a plurality of color components of the object are selected,
the determining a target color value of the second pixel point further includes:
judging whether the target transparency component is larger than a first color component, wherein the first color component is any one of a plurality of color components of the first pixel point;
when the target transparency component is larger than the first color component, determining the target transparency component as a first target color component, wherein the first target color component is a target color component corresponding to the first color component in the plurality of target color components.
Optionally, the method further comprises:
determining the first color component as the first target color component when the target transparency component is not greater than the first color component.
Optionally, the method further comprises:
and if the color component of the first pixel point is not different from the pre-configured color component of the corresponding pixel point of the character to be drawn, drawing the second pixel point on the target base map by adopting the color value of the first pixel point.
Optionally, the obtaining the transparency component of the first pixel point includes:
determining an average value of a plurality of color components of the first pixel point;
and determining the average value as the transparency component of the first pixel point.
Optionally, the determining the target transparency component according to the transparency component of the target base map and the transparency component of the first pixel point includes:
based on the transparency component of the target base map and the transparency component of the first pixel point, determining the target transparency component according to a target transparency component calculation formula, wherein the target transparency component calculation formula is as follows: TargetA ═ (1- (1-textA/255) × (1-backsa/255)) × 255;
wherein, the targetA is the target transparency component, the textA is the transparency component of the first pixel point, and the backsA is the transparency component of the target base map.
Optionally, the plurality of color components comprises: a red color component, a green color component, and a blue color component.
In a second aspect, there is provided a text drawing apparatus comprising:
the system comprises a first drawing module, a second drawing module and a third drawing module, wherein the first drawing module is used for drawing characters to be drawn on a temporary base map by adopting a preset color value of each pixel point of the characters to be drawn, each character consists of a plurality of pixel points, the color value comprises a transparency component and a plurality of color components, the transparency component and the color component of all the pixel points in the temporary base map are both 0, and the characters to be drawn are characters to be drawn on a target base map;
the comparison module is used for comparing whether the color component of a first pixel point on the temporary base map is different from the pre-configured color component of a corresponding pixel point of the character to be drawn or not, wherein the first pixel point is any pixel point drawn on the temporary base map;
a determining module, configured to determine a target color value of a second pixel point if a color component of a first pixel point on the temporary base map differs from a preconfigured color component of a corresponding pixel point of the character to be drawn, where the target color value is obtained based on the color component of the first pixel point and a transparency of the target base map, and the second pixel point is a pixel point of the character to be drawn corresponding to the first pixel point;
and the second drawing module is used for drawing a second pixel point on the target base map by adopting the target color value.
Optionally, the contrast between the target color value and the target base map is smaller than the contrast between the color value of the first pixel point and the target base map.
Optionally, the target color values comprise: a target transparency component, the determining module comprising:
the first obtaining submodule is used for obtaining a transparency component of the target base map;
the second obtaining submodule is used for obtaining the transparency component of the first pixel point, and the transparency component of the first pixel point is determined according to the color component of the first pixel point;
and the first determining submodule is used for determining the target transparency component according to the transparency component of the target base map and the transparency component of the first pixel point.
Optionally, the target color values comprise: a plurality of color components of the object are selected,
the determining module further comprises:
the judgment submodule is used for judging whether the target transparency component is larger than a first color component, wherein the first color component is any one of a plurality of color components of the first pixel point;
a second determining sub-module, configured to determine the target transparency component as a first target color component when the target transparency component is greater than the first color component, where the first target color component is a target color component corresponding to the first color component in the multiple target color components.
Optionally, the determining module further comprises:
a third determining sub-module for determining the first color component as the first target color component when the target transparency component is not greater than the first color component.
Optionally, the apparatus further comprises:
and the third drawing module is used for drawing the second pixel point on the target base map by adopting the color value of the first pixel point if the color component of the first pixel point is not different from the color component which is configured in advance of the corresponding pixel point of the character to be drawn.
Optionally, the second obtaining sub-module is specifically configured to:
determining an average value of a plurality of color components of the first pixel point;
and determining the average value as the transparency component of the first pixel point.
Optionally, the first determining submodule is specifically configured to:
based on the transparency component of the target base map and the transparency component of the first pixel point, determining the target transparency component according to a target transparency component calculation formula, wherein the target transparency component calculation formula is as follows: TargetA ═ (1- (1-textA/255) × (1-backsa/255)) × 255;
wherein, the targetA is the target transparency component, the textA is the transparency component of the first pixel point, and the backsA is the transparency component of the target base map.
Optionally, the plurality of color components comprises: a red color component, a green color component, and a blue color component.
In a third aspect, a storage medium is provided, where instructions are stored, and when the storage medium runs on a computer, the computer is caused to execute the text drawing method according to any one of the first aspect.
In a fourth aspect, a terminal is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the method for drawing a text according to any one of the first aspect is implemented.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
in the text rendering method and apparatus, the terminal and the storage medium provided in the embodiments of the present invention, by comparing whether a color component of a first pixel point on the temporary base map differs from a color component of a corresponding pixel point of the text to be rendered, when the color component of the first pixel point differs from a transparency of the target base map, a target color value of a pixel point corresponding to the first pixel point of the text to be rendered is determined based on the color component of the first pixel point and the transparency of the target base map, and a target color value is used to render a second pixel point on the target base map.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
In some application scenarios, in order to improve the display effect of the displayed image, it is generally required to draw a text with a certain transparency and color in the target base map of the image, for example: when making a poster, some characters need to be drawn in the target base map with the pattern so as to improve the display effect of the poster. In the related art, when a GDI and a text drawing function are used to draw a text in a target base map with a certain transparency and color, since the influence of the target base map on the drawn text is not considered, a difference between the color of the text drawn in the target base map and an expected color may occur, for example: when black characters are drawn on a white target base map with certain transparency by using the GDI and the character drawing function, the drawn characters have black outlines, and the colors of the drawn characters are different from expected colors because the black outlines are not the contents originally intended to be drawn. To solve the problem, the embodiment of the invention provides a character drawing method. Fig. 1 is a flowchart of a text rendering method according to an embodiment of the present invention, and as shown in fig. 1, the method may include:
step 101, drawing the character to be drawn on the temporary base map by using the preset color value of each pixel point of the character to be drawn.
Each character consists of a plurality of pixel points, the color value comprises a transparency component and a plurality of color components, the transparency components and the color components of all the pixel points in the temporary base map are 0, and the character to be drawn is the character to be drawn on the target base map.
And 102, comparing whether the color component of the first pixel point on the temporary base map is different from the pre-configured color component of the corresponding pixel point of the character to be drawn.
The first pixel point is any pixel point drawn on the temporary base map.
And 103, if the color component of the first pixel point on the temporary base map is different from the pre-configured color component of the corresponding pixel point of the character to be drawn, determining the target color value of the second pixel point.
The target color value is obtained based on the color component of the first pixel point and the transparency of the target base map, and the second pixel point is a pixel point of the character to be drawn, which corresponds to the first pixel point.
And 104, drawing a second pixel point on the target base map by adopting the target color value.
In summary, in the text rendering method provided in the embodiment of the present invention, by comparing whether there is a difference between a color component of a first pixel point on the temporary base map and a color component configured in advance for a pixel point corresponding to the text to be rendered, and when there is a difference between the two, based on the transparency of the color component of the first pixel point and the target base map, a target color value of the pixel point corresponding to the first pixel point of the text to be rendered is determined, and a target color value is used to render a second pixel point on the target base map.
Fig. 2 is a flowchart of another text rendering method according to an embodiment of the present invention, and as shown in fig. 2, the method may include:
step 201, using the preset color value of each pixel point of the character to be drawn, drawing the character to be drawn on the temporary base map.
Wherein, the color value of pixel point can include transparency component and a plurality of color component, and this a plurality of color component can include: the embodiment of the present invention does not limit this, and the transparency components and the color components of all pixel points in the temporary base map may be 0, so that the influence on the color values of the pixel points drawn on the temporary base map may be reduced to a greater extent.
For example, assuming that the preconfigured color value of a certain pixel point of the text to be rendered is (255, 0, 0), the pixel point may be rendered on the temporary base map by using the color value (255, 0, 0).
Step 202, obtaining a color value of a first pixel point drawn on the temporary base map.
When a first pixel point is drawn on a temporary base map, the first pixel point is generally drawn in the neighborhood of the drawn pixel point, the color value of the drawn pixel point may have a certain influence on the color value of the first pixel point, the influence is usually expressed as making the color of the drawn first pixel point brighter, so that the color value of the drawn first pixel point is smaller than the pre-configured color value, that is, the color component of the first pixel point may be different from the pre-configured color component, therefore, before the pixel point of the character to be drawn is drawn on the target base map, the color value of the first pixel point drawn on the temporary base map needs to be obtained first, and then whether a plurality of color components in the color value of the first pixel point on the temporary base map are different from the pre-configured color component of the corresponding pixel point of the character to be drawn or not needs to be compared, and then determining how to draw a pixel point corresponding to the first pixel point of the character to be drawn on the target base map according to the comparison result.
Step 203, comparing whether the color component of the first pixel point on the temporary base map is different from the pre-configured color component of the corresponding pixel point of the character to be drawn.
When any color component of the first pixel point is not equal to the corresponding color component of the corresponding pixel point of the character to be drawn, the color component of the first pixel point is considered to be different from the color component of the corresponding pixel point of the character to be drawn, and at this time, step 204 is executed; when all the color components of the first pixel point are equal to the color components pre-configured for the corresponding pixel point of the character to be drawn, it can be determined that there is no difference between the color components, and at this time, step 206 is executed.
Exemplarily, assuming that the color value of the first pixel point is (128, 128, 2), the preconfigured color component of the corresponding pixel point of the text to be drawn is (255, 0, 0), when comparing the red color component of the color value, the red color component of the first pixel point is 128, the preconfigured red color component of the corresponding pixel point of the text to be drawn is 255, and it is known that the color component of the first pixel point is different from the preconfigured color component of the corresponding pixel point of the text to be drawn, step 204 is executed.
And 204, if the color component of the first pixel point on the temporary base map is different from the pre-configured color component of the corresponding pixel point of the character to be drawn, determining the target color value of the second pixel point.
Because the target color value is obtained based on the color component of the first pixel point and the transparency of the target base map, the obtained target color value comprehensively considers the influence of the color component of the first pixel point and the target base map, and the contrast between the target color value and the target base map is smaller than the contrast between the color value of the first pixel point and the target base map. Optionally, the target color values may include: a target transparency component. Specifically, as shown in fig. 3, the process of determining the target color value of the second pixel point may include:
and 2041, obtaining a transparency component of the target base map.
In the method for drawing characters provided by the embodiment of the invention, the characters are drawn on the target base map drawn with the image, and the transparency component and the color component of the pixel point in the image of the target base map drawn with the image are known, so that the transparency component of the target base map can be obtained by detecting the transparency component of the pixel point and the like. Illustratively, assume that the transparency component of the acquired target base map is 191.
Step 2042, the transparency component of the first pixel point is obtained.
Optionally, the transparency component of the first pixel point may be determined according to the color component of the first pixel point, specifically, an average value of the color components may be determined according to the color components of the first pixel point, and then the average value is determined as the transparency component of the first pixel point.
For example, assuming that the color value of the first pixel is (128, 128, 2), and the average value of the 3 color components is (128+128+2)/3 ═ 86, the average value 86 may be determined as the transparency component of the first pixel, i.e., the obtained transparency component of the first pixel is 86.
And 2043, determining a target transparency component according to the transparency component of the target base map and the transparency component of the first pixel point.
Specifically, the target transparency component may be determined according to a target transparency component calculation formula based on the transparency component of the target base map and the transparency component of the first pixel point, where the target transparency component calculation formula is: TargetA ═ (1- (1-textA/255) × (1-backsa/255)) × 255.
Wherein, targetA is the transparency component of the target, textA is the transparency component of the first pixel point, and back A is the transparency component of the target base map.
For example, assuming that the transparency component backsa of the target base map is 191 and the transparency component textA of the first pixel point is 86, the target transparency component TargetA is (1- (1-86/255) × (1-191/255)) × 255 is 213.
Step 2044, determine whether the target transparency component is greater than the first color component.
The first color component is any one of the color components of the first pixel, that is, the first color component may be any one of a red color component, a green color component, or a blue color component.
Optionally, the target color value of the second pixel point may be determined according to the target transparency component and the first color component, and the determined target color value and the target transparency component determined in step 2043 form the target color value of the second pixel point together. Specifically, it may be determined whether the target transparency component is greater than the first color component, and when the target transparency component is greater than the first color component, step 2045 is performed, and when the target transparency component is not greater than the first color component, step 2046 is performed.
Exemplarily, assuming that the first color component is 128, the target transparency component is 213, and the target transparency component is greater than the first color component, step 2045 is performed.
Step 2045, when the target transparency component is greater than the first color component, determine the target transparency component as the first target color component.
The first target color component is a target color component corresponding to the first color component in the plurality of target color components.
When the target transparency component is larger than the first color component, the target transparency component is closer to the pre-configured color component, and therefore, the target transparency component can be determined as the first target color component to reduce the difference between the color of the drawn text and the expected color.
For example, assuming that the first color component is 128, the target transparency component is 213, and the target transparency component is greater than the first color component, the target transparency component may be determined as the first target color component, i.e., the first target color component is 213.
As can be seen from the above, the preconfigured color component of a certain pixel of the text to be drawn is 255, the corresponding first color component of the first pixel drawn on the temporary base map is 128, and the corresponding first target color component is 213, and the first target color component is closer to the preconfigured color component than the first color component drawn on the temporary base map, and when the pixel is drawn on the target base map by using the color component, the difference between the color of the drawn text and the preconfigured color can be reduced.
Step 2046, when the target transparency component is not greater than the first color component, determine the first color component as the first target color component.
When the target transparency component is not larger than the first color component, the first color component is closer to the pre-configured color component, and therefore, the first color component can be determined as the first target color component, so as to reduce the difference between the color of the drawn text and the expected color.
For example, assuming that the first color component is 228, the target transparency component is 213, and the target transparency component is smaller than the first color component, the first color component may be determined as the first target color component, i.e., the first target color component is 228.
In practical application, in the process of determining the target color value of the second pixel point, only step 2041 to step 2043 may be included, that is, the target transparency component may be determined only according to the transparency component of the target base map and the transparency component of the first pixel point, and then the determined target transparency component and the plurality of color components of the first pixel point are determined as the target color value of the second pixel point, so as to reduce the difference between the color of the drawn text and the expected color to a certain extent.
In practical applications, steps 2044 to 2046 may be performed on each color component of the first pixel, which is only an example of the first color component in the embodiment of the present invention, and the determining process of the target color component of the other color components in the first pixel may refer to the determining process of the first target color component, which is not described in detail in the embodiment of the present invention.
And step 205, drawing a second pixel point on the target base map by adopting the target color value.
After the target color value of the second pixel point is determined according to the color component of the first pixel point and the transparency of the target base map, the second pixel point can be drawn according to the determined target color value.
For example, assuming that on a white target base map (whose color value is (0, 0, 0)), the preconfigured color of each pixel point of the text to be drawn is black (whose color value is (255, 255, 255)), referring to fig. 4 for a schematic diagram of the text drawn on the target base map according to the preconfigured color value by using a text drawing method of the related art, referring to fig. 5 for a schematic diagram of the text drawn on the target base map according to the preconfigured color value by using a text drawing method provided by an embodiment of the present invention, as can be obtained by comparing fig. 4 and fig. 5, a layer of black shadow appears on the text drawn by using a text drawing method of the related art, and the difference between the color of the drawn text and the preconfigured color value is large, the text drawn by using the text drawing method provided by the embodiment of the present invention has almost no shadow, and the difference between the color of the drawn character and the preset color value is smaller, so that the color of the character drawn by using the character drawing method provided by the embodiment of the invention is closer to the expected color, and the accuracy of the color of the drawn character is improved.
And step 206, if the color component of the first pixel point is not different from the color component of the corresponding pixel point of the character to be drawn, drawing a second pixel point on the target base map by adopting the color value of the first pixel point.
The color component of the first pixel point and the color component of the corresponding pixel point of the character to be drawn which is configured in advance do not have difference, that is, the color component of the first pixel point and the color component of the corresponding pixel point of the character to be drawn which is configured in advance are equal, when the character is drawn according to the color component, the influence of the target base map on the drawn character can be reduced to the minimum, therefore, the color value of the first pixel point can be adopted to directly draw the second pixel point on the target base map.
In practical applications, steps 201 to 206 may be performed on each pixel point of the text to be drawn, the embodiment of the present invention is only described with reference to the first pixel point as an example, and the drawing process of other pixel points of the text to be drawn may refer to the drawing process of the first pixel point, which is not described in detail in the embodiment of the present invention.
In summary, in the text rendering method provided in the embodiment of the present invention, by comparing whether there is a difference between a color component of a first pixel point on the temporary base map and a color component configured in advance for a pixel point corresponding to the text to be rendered, and when there is a difference between the two, based on the transparency of the color component of the first pixel point and the target base map, a target color value of the pixel point corresponding to the first pixel point of the text to be rendered is determined, and a target color value is used to render a second pixel point on the target base map.
It should be noted that the order of the steps of the text drawing method provided by the embodiment of the present invention may be appropriately adjusted, and the steps may also be increased or decreased according to the situation. Any method that can be easily conceived by those skilled in the art within the technical scope of the present disclosure is covered by the protection scope of the present disclosure, and thus, the detailed description thereof is omitted.
An embodiment of the present invention provides a text drawing apparatus, as shown in fig. 6, the apparatus 600 may include:
the first drawing module 601 is configured to draw the text to be drawn on the temporary base map by using a preconfigured color value of each pixel point of the text to be drawn, where each text is composed of a plurality of pixel points, the color value includes a transparency component and a plurality of color components, the transparency component and the color component of all the pixel points in the temporary base map are both 0, and the text to be drawn is the text to be drawn on the target base map.
The comparing module 602 is configured to compare whether there is a difference between a color component of a first pixel point on the temporary base map and a color component configured in advance for a corresponding pixel point of the text to be drawn, where the first pixel point is any pixel point drawn on the temporary base map.
The determining module 603 is configured to determine a target color value of a second pixel point if a color component of a first pixel point on the temporary base map differs from a preconfigured color component of a corresponding pixel point of the text to be drawn, where the target color value is obtained based on the color component of the first pixel point and a transparency of the target base map, and the second pixel point is a pixel point of the text to be drawn corresponding to the first pixel point.
And a second rendering module 604, configured to render a second pixel point on the target base map by using the target color value.
In summary, in the text rendering apparatus provided in the embodiment of the present invention, the comparison module compares whether the color component of the first pixel point on the temporary base map is different from the color component of the corresponding pixel point of the text to be rendered, and when the color component of the first pixel point is different from the color component of the target base map, the determination module determines the target color value of the pixel point corresponding to the first pixel point of the text to be rendered, and the second rendering module renders the second pixel point on the target base map by using the target color value.
Optionally, the contrast between the target color value and the target base map is smaller than the contrast between the color value of the first pixel point and the target base map.
Optionally, the target color values comprise: the target transparency component, as shown in fig. 7, the determining module 603, may include:
the first obtaining sub-module 6031 is configured to obtain a transparency component of the target base map.
The second obtaining sub-module 6032 is configured to obtain a transparency component of the first pixel point, where the transparency component of the first pixel point is determined according to the color component of the first pixel point.
The first determining submodule 6033 is configured to determine a transparency component of the target according to the transparency component of the target base map and the transparency component of the first pixel point.
Optionally, the target color values comprise: the plurality of target color components, as shown in fig. 7, the determining module 603 may further include:
the determining submodule 6034 is configured to determine whether the target transparency component is greater than a first color component, where the first color component is any color component of the multiple color components of the first pixel point.
The second determining sub-module 6035 is configured to determine the target transparency component as the first target color component when the target transparency component is larger than the first color component, where the first target color component is a target color component corresponding to the first color component in the plurality of target color components.
Optionally, as shown in fig. 7, the determining module 603 may further include:
a third determining sub-module 6036 for determining the first color component as the first target color component when the target transparency component is not greater than the first color component.
Optionally, as shown in fig. 8, the apparatus 600 may further include:
the third drawing module 605 is configured to draw a second pixel point on the target base map by using the color value of the first pixel point if there is no difference between the color component of the first pixel point and the preconfigured color component of the corresponding pixel point of the character to be drawn.
Optionally, the second obtaining sub-module 6032 may specifically be configured to:
and determining the average value of the plurality of color components of the first pixel point.
And determining the average value as the transparency component of the first pixel point.
Optionally, the first determining sub-module 6033 may specifically be configured to:
based on the transparency component of the target base map and the transparency component of the first pixel point, determining the target transparency component according to a target transparency component calculation formula, wherein the target transparency component calculation formula is as follows: TargetA ═ (1- (1-textA/255) × (1-backsa/255)) × 255.
Wherein, targetA is the transparency component of the target, textA is the transparency component of the first pixel point, and back A is the transparency component of the target base map.
Optionally, the plurality of color components comprises: a red color component, a green color component, and a blue color component.
In summary, in the text rendering apparatus provided in the embodiment of the present invention, the comparison module compares whether the color component of the first pixel point on the temporary base map is different from the color component of the corresponding pixel point of the text to be rendered, and when the color component of the first pixel point is different from the color component of the target base map, the determination module determines the target color value of the pixel point corresponding to the first pixel point of the text to be rendered, and the second rendering module renders the second pixel point on the target base map by using the target color value.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, modules and sub-modules may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The embodiment of the invention also provides a storage medium, wherein the storage medium is stored with instructions, and when the storage medium runs on a computer, the computer is enabled to execute the character drawing method provided by the method embodiment.
The embodiment of the invention also provides a terminal which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein when the processor executes the computer program, the character drawing method provided by the embodiment of the method is realized.
The embodiment of the invention also provides a computer program product containing instructions, which when running on a computer, enables the computer to execute the character drawing method provided by the method embodiment.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.