Watermark generation method and apparatus
By creating a watermark layer with rich text attributes through the watermark drawing interface, and drawing and adding watermarks asynchronously, the problem of low efficiency in traditional watermark generation is solved, achieving efficient rendering and generation of diverse watermarks, and improving security.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2021-09-28
- Publication Date
- 2026-07-24
AI Technical Summary
Traditional watermark generation methods are inefficient, affecting loading efficiency, especially when rendering multiple watermarks or multiple images.
The system uses a watermark drawing interface to create watermark layers with rich text attributes. Watermarks are drawn and added asynchronously via a thread. The UIView class is extended using a categorization approach to support the drawing and adding of watermarks in rich text format.
It improves watermark rendering efficiency, supports diverse watermarks that combine text and images, enhances image security, and reduces the risk of tampering and theft.
Smart Images

Figure CN115880123B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a watermark generation method and apparatus. Background Technology
[0002] In certain scenarios (such as taking screenshots of pages, sending images via instant messaging, sharing images, etc.), it is necessary to add watermarks to the current page or view to protect information from being stolen.
[0003] In traditional techniques, each watermark generation requires calling an initialization function, initializing the layer, and then calling the watermark rendering function, which is a relatively complex process. If there are too many watermarks or too many images to render, it will affect the loading efficiency and result in low watermark rendering efficiency. Summary of the Invention
[0004] Therefore, it is necessary to provide a watermark generation method, apparatus, computer equipment, and storage medium that can improve watermark rendering efficiency in response to the above-mentioned technical problems.
[0005] A watermark generation method, the method comprising:
[0006] In response to a watermark addition command, the target image and watermark parameters corresponding to the watermark addition command are obtained;
[0007] Call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark layer with the drawn watermark to the target image.
[0008] A watermark generation apparatus, the apparatus comprising:
[0009] The acquisition module is used to acquire the target image and watermark parameters corresponding to the watermark addition command in response to the watermark addition command;
[0010] The calling module is used to call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark layer with the drawn watermark to the target image.
[0011] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program performing the following steps:
[0012] In response to a watermark addition command, the target image and watermark parameters corresponding to the watermark addition command are obtained;
[0013] Call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark layer with the drawn watermark to the target image.
[0014] A computer-readable storage medium having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0015] In response to a watermark addition command, the target image and watermark parameters corresponding to the watermark addition command are obtained;
[0016] Call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark layer with the drawn watermark to the target image.
[0017] A computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0018] In response to a watermark addition command, the target image and watermark parameters corresponding to the watermark addition command are obtained;
[0019] Call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark layer with the drawn watermark to the target image.
[0020] The aforementioned watermark generation method, apparatus, computer equipment, computer-readable storage medium, and computer program product, in response to a watermark addition instruction, acquire the target image and watermark parameters corresponding to the watermark addition instruction; call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark-drawn watermark layer to the target image. Accordingly, the watermark addition operation is encapsulated into an interface, and watermark rendering can be completed by calling this single interface, improving watermark rendering efficiency. Furthermore, by supporting the drawing of rich text format watermarks through the rich text attribute watermark layer, mixed text and image layouts can be achieved, increasing the diversity of watermarks. Moreover, the drawn rich text watermarks are not easily removed, reducing the risk of image tampering and theft, and improving security. Attached Figure Description
[0021] Figure 1 This is a diagram illustrating the application environment of a watermark generation method in one embodiment.
[0022] Figure 2 This is a flowchart illustrating a watermark generation method in one embodiment;
[0023] Figure 3This is a schematic diagram of the core drawing API in one embodiment;
[0024] Figure 4 This is a schematic diagram of the watermark effect in one embodiment;
[0025] Figure 5 This is a schematic diagram of the watermark effect in one embodiment;
[0026] Figure 6 This is a flowchart illustrating a watermark generation method in one embodiment;
[0027] Figure 7 This is a flowchart illustrating the process of drawing a single watermark in one embodiment;
[0028] Figure 8 This is a structural block diagram of a watermark generation device in one embodiment;
[0029] Figure 9 This is an internal structural diagram of a computer device in one embodiment;
[0030] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0032] The watermark generation method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. Users can access an application with watermarking functionality through terminal 102, and server 104 can be the server hosting that application. The watermark generation method can be applied to terminal 102 with the application installed, to server 104 where the application resides, or to a system including terminal 102 and server 104, and is implemented through interaction between terminal 102 and server 104. Server 104 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. Terminal 102 includes, but is not limited to, mobile phones, computers, smart voice interaction devices, smart home appliances, and in-vehicle terminals. Terminal 102 and server 104 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0033] In one embodiment, such as Figure 2 As shown, a watermark generation method is provided, which can be applied to... Figure 1 The following steps are used as an example of the terminal in the example, including steps S202 to S204.
[0034] S202, in response to the watermark addition command, obtain the target image and watermark parameters corresponding to the watermark addition command.
[0035] The watermark addition command is used to trigger the watermark addition operation. The form of the watermark addition command can be set according to different scenarios, and there are no restrictions here. For example, when the terminal detects a page screenshot, image sending, or image sharing operation, it can be considered that it has received a watermark addition command and needs to add a watermark to the corresponding image.
[0036] The target image refers to the image to which the watermark needs to be added. Watermark parameters refer to the parameters to be added to the watermark, used to characterize the watermark content, watermark format, and other information. For example, if the watermark is in text format, the corresponding watermark content includes, but is not limited to, the text content, and the watermark format includes, but is not limited to, font and font size; if the watermark is in image format, the corresponding watermark content includes, but is not limited to, the image content, and the watermark format includes, but is not limited to, the image size; if the watermark is in rich text format, which includes both images and text, the corresponding watermark content includes, but is not limited to, both images and text content, and the watermark format includes, but is not limited to, image size, font, font size, and the arrangement of the image and text.
[0037] S204, call the watermark drawing interface, create a watermark layer with rich text attributes through the watermark drawing interface, draw the watermark on the watermark layer based on the watermark parameters, and add the watermark layer with the drawn watermark to the target image.
[0038] The watermark drawing interface is used to implement watermark drawing and addition, that is, to generate watermarks on target images. For example, for iOS and Mac devices, the Core Animation application programming interface (API) can be used to draw layers through the CATextLayer class to achieve watermark drawing. Rich text attribute watermark layers support drawing both plain text watermarks and plain image watermarks, as well as rich text watermarks (i.e., watermarks that include both text and images). In one embodiment, such as... Figure 3 As shown, a schematic diagram of the core drawing API is provided. In CATextLayer, the string property type belongs to the id type, and the comment indicates that it can be the NSAttributedString string type, which means that rich text drawing is supported.
[0039] In one embodiment, the watermark drawing interface is constructed based on the classification of interface view classes.
[0040] A UIView can be understood as a canvas for drawing. Using UIView as the base class, the watermark drawing interface is applied within UIView categories. Current methods of adding subclasses typically reuse code. However, when subclasses override certain methods of the base class, they break its encapsulation mechanism, affecting the efficiency of feature expansion and the effectiveness of encapsulation. Categories, a unique syntax in Objective-C, represent a pointer to a structure that, in principle, can only add methods, not member variables (these can be dynamically added or removed at runtime). Using categories to add extension methods to UIView for watermark drawing ensures that all the functionality of the base class is implemented and allows for flexible extension of related functions, improving the efficiency of feature expansion and the effectiveness of encapsulation, while reducing code development costs.
[0041] Specifically, the UIView class, UIView+TXWatermark, is created, which provides an instance method for adding a watermark (an instance method can be understood as an object method, called by an object of type UIView). It receives watermark parameters from the outside and draws and adds the watermark.
[0042] In one embodiment, before calling the watermark drawing interface, the following steps are also included: obtaining the category header file corresponding to the watermark adding instruction, the category header file including a method index; and obtaining the method corresponding to the watermark drawing interface from the method list of the interface view class according to the method index.
[0043] During compilation, developers add the category methods to the method list of the original class (UIView) and configure the category header file. The header file includes the index of the category methods, which is used to query the required category methods from the UIView's method list.
[0044] The method corresponding to the watermark drawing interface is the method for adding a watermark. When a watermark adding instruction is received, the category header file corresponding to the watermark adding instruction is obtained. The method for adding a watermark is obtained from the method list of UIView through the method index in the category header file. When the watermark drawing interface is called, the watermark is generated on the target image through the method for adding a watermark.
[0045] Watermark parameters can be passed as dictionary parameters in key-value pairs, where the key represents the field and the value represents the value. The data fields are described below: Watermark_text (watermark text, string type), Watermark_image (watermark image, string type, including local and online image URLs), and AttributeValue (rich text attributes, including foreground color, background color, font italics, font bold, letter spacing, underline, underline color, stroke, shadow, and horizontal / vertical orientation). External parameters can be selectively passed to these fields, while internal parameters can have preset default values.
[0046] In the above watermark generation method, in response to a watermark addition command, the target image and watermark parameters corresponding to the command are obtained; the watermark drawing interface is called to create a watermark layer with rich text attributes; the watermark is drawn on the watermark layer based on the watermark parameters; and the watermark layer is added to the target image. Thus, the watermark addition operation is encapsulated into a single interface, allowing watermark rendering to be completed by calling this single interface, improving rendering efficiency. Furthermore, the rich text attribute watermark layer supports drawing rich text format watermarks, enabling mixed text and image layouts, increasing watermark diversity, and making the drawn rich text watermarks difficult to remove, reducing the risk of image tampering and theft, and improving security.
[0047] In one embodiment, the steps of creating a watermark layer with rich text attributes through a watermark drawing interface, drawing a watermark on the watermark layer based on watermark parameters, and adding the watermark layer to the target image may specifically include: starting a sub-thread through the watermark drawing interface, with the sub-thread executing asynchronously with the main thread; creating a watermark layer with rich text attributes through the sub-thread, drawing a watermark on the watermark layer based on watermark parameters, and adding the watermark layer to the target image.
[0048] Asynchronous execution refers to starting a sub-thread while the main thread is executing. Unlike synchronous execution, the main thread does not wait for the sub-thread's result to return before continuing; instead, it continues execution. When the main thread needs the sub-thread's result, it directly calls it. In this embodiment, after starting the sub-thread, the main thread can handle other UI refresh events, such as receiving user clicks, touches, and swipes. After the sub-thread finishes drawing, the main thread dispatches the rendering completion callback. Therefore, by using asynchronous execution of the sub-thread for watermark drawing and addition, the main thread's execution is not blocked, avoiding impact on the main thread and improving processing efficiency.
[0049] Specifically, when a view type calls addWaterMark, a concurrent queue (ConcurrentQueue) can be created through Grand Central Dispatch (GCD), a central scheduling technology that supports multi-core processors, to start an asynchronous task (async) for adding watermarks to the passed-in view. When multiple views need to be watermarked at the same time, they can be processed in parallel through ConcurrentQueue.
[0050] In one embodiment, the step of drawing a watermark on a watermark layer based on watermark parameters may specifically include the following steps: parsing the watermark parameters to obtain the watermark content and watermark format; and drawing the watermark content onto the watermark layer according to the watermark format.
[0051] Parsing the watermark parameters yields metadata used to render a single watermark. This metadata contains the watermark content and format, which includes, but is not limited to, images and text. The watermark format includes, but is not limited to, image size, font, font size, and the arrangement of the image and text. Specifically, a `CATextLayer` object is created, its `string` property is set to `NSAttributedString`, and the font, font size, line spacing, and other properties of the rich text are set to obtain the rich text watermark layer. If a single watermark includes both an image and text, the image and text are drawn onto the watermark layer according to their size, font, font size, and arrangement.
[0052] In one embodiment, after obtaining the watermark content and watermark format, the following steps may also be included: determining the width and height of a single watermark based on the watermark content and watermark format through the watermark drawing interface, and determining the total number of rows and columns based on the width and height of the single watermark, the watermark spacing, and the width and height of the target image.
[0053] The width and height of a single watermark include both the width and height of the watermark itself. For example, if the watermark is a plain text watermark, its width and height can be calculated by combining the text content, font, and font size; if the watermark is a plain image watermark, its width and height can be obtained based on the image size; if the watermark is a rich text watermark, its width and height can be calculated by combining the image and text content, image size, font, font size, and the arrangement of the image and text.
[0054] Watermark spacing refers to the distance between adjacent watermarks when multiple repeating watermarks are added to a target image. It can include horizontal and vertical spacing, which can be the same or different. Total rows represent the number of repeating watermarks arranged horizontally on the target image. Total columns represent the number of repeating watermarks arranged vertically on the target image. When multiple repeating watermarks need to be added to a target image, the total number of rows and columns can be calculated based on the width and height of each watermark, the watermark spacing, and the width and height of the target image.
[0055] Specifically, the width (W) and height (H) of the view (i.e., the target image) to which the watermark needs to be added can be obtained through the constructors self.width and self.height. Let the width and height of the currently drawn canvas be W and H, respectively. The size (textSize) of a single watermark is generated by calling the sizeWithAttributes method, including the width (size.width) and height (size.height) of a single watermark. Then, the total number of lines and columns of the watermark are calculated based on size.width, size.height, W, H, and the preset watermark spacing.
[0056] In one embodiment, the step of creating a watermark layer with rich text attributes through the watermark drawing interface may specifically include the following steps: determining the number of watermarks based on the total number of rows and columns through the watermark drawing interface, and creating a watermark layer with rich text attributes representing the number of watermarks.
[0057] The number of watermarks is determined based on the total number of rows and columns; specifically, the product of the total number of rows and columns can be used as the number of watermarks. A rich text attribute for the number of watermarks is created, and a single watermark is drawn on each watermark layer. Multiple drawing processes are performed concurrently using asynchronous threads, thereby improving the efficiency of drawing multiple watermarks.
[0058] In one embodiment, the step of adding a watermark layer to a target image may include the following steps: for each watermark layer, determine the corresponding addition position of the watermark layer in the target image based on the row number and column number of the watermark layer, and add the watermark layer to the target image according to the addition position.
[0059] A coordinate system can be established with the top-left corner of the target image as the origin, the rightward direction as the positive x-axis, and the downward direction as the positive y-axis. The position of the watermark layer in the target image can be the coordinate position of the top-left corner of the watermark layer in this coordinate system. After determining the total number of rows, columns, and watermarks, the watermark layers can be sorted horizontally from left to right and vertically from top to bottom. For example, if there are 5 rows and 3 columns, with a total of 15 watermarks, then the 1st watermark layer corresponds to the 1st row and 1st column, the 2nd watermark layer to the 1st row and 2nd column, ..., the 4th watermark layer to the 2nd row and 1st column, the 5th watermark layer to the 2nd row and 2nd column, ..., the 13th watermark layer to the 5th row and 1st column, the 14th watermark layer to the 5th row and 2nd column, and the 15th watermark layer to the 5th row and 3rd column.
[0060] The first coordinate position of the top-left vertex of the first watermark layer in the coordinate system can be preset to determine its placement in the target image. For other watermark layers, the coordinate position of the top-left vertex of the watermark layer in the coordinate system can be calculated based on the first coordinate position, the row and column numbers of the watermark layer, as well as the width, height, and spacing of each watermark, thus determining its placement in the target image.
[0061] After obtaining the corresponding addition positions of each watermark layer in the target image, the watermark layers are added to their respective positions in the target image, thus generating multiple watermarks on the target image. For example... Figure 4 and Figure 5 As shown, each of the above provides a schematic diagram of the watermark effect in an embodiment. Figure 4 The watermark is a plain text watermark. Figure 5 The watermark is a rich text watermark.
[0062] In one embodiment, for each watermark layer, the following steps may also be included: obtaining the watermark rotation angle of the watermark layer. The step of adding the watermark layer to the target image based on the addition position may specifically include the following steps: rotating the watermark layer based on the watermark rotation angle, and adding the rotated watermark layer to the target image based on the addition position.
[0063] Watermark rotation angle refers to the angle of the watermark relative to the horizontal or vertical direction when it is added to the target image. When multiple watermarks are arranged on the target image, the rotation angles of watermarks in different positions can be the same or different, thus supporting watermark diversity. For example, if the watermark rotation angles of watermarks in different positions are the same, such as all being rotated 45° counterclockwise relative to the positive horizontal axis, then after drawing the watermark on each watermark layer, each watermark layer is rotated 45° counterclockwise relative to the positive horizontal axis before being added to the target image.
[0064] In one embodiment, the step of determining the watermark rotation angle of the watermark layer may specifically include the following steps: determining the sequence number of the watermark layer according to the row number and column number of the watermark layer; taking the remainder of the sequence number of the watermark layer with respect to the total number of rows or columns; and determining the watermark rotation angle of the watermark layer based on the remainder obtained by taking the remainder and the preset rotation angle.
[0065] To achieve different rotation angles for watermarks in different locations, the rotation angle can be determined based on the watermark layer's index. Specifically, different watermark layers have different indices. Taking the remainder of each watermark layer's index modulo the total number of rows or columns yields different remainders. Multiplying these remainders by a preset rotation angle results in different rotation angles for each watermark layer. Therefore, by taking the remainder of each watermark layer modulo the total number of rows or columns, you can quickly obtain differentiated rotation angles for multiple watermarks, improving the drawing efficiency of watermarks with varying rotation angles.
[0066] For example, if there are 5 rows and 3 columns, and the three watermark layers in the first row are numbered 1, 2, and 3 from left to right, for the first watermark layer, take the remainder of its number divided by the total number of rows. If the remainder is 1, and assuming a preset rotation angle of 20°, then the watermark rotation angle of the first watermark layer is 20°. Similarly, the watermark rotation angle of the second watermark layer is 40°, and the watermark rotation angle of the third watermark layer is 0°. The watermark rotation angles for the watermark layers in rows 2-5 can be calculated using a similar method. Therefore, watermarks in different positions have different watermark rotation angles, further improving the diversity of watermark display. Furthermore, the watermarks are not easily removed, reducing the risk of image tampering and theft, and improving security.
[0067] In one embodiment, such as Figure 6 As shown, a watermark generation method is provided, including the following steps S610 to S630:
[0068] S610, creating UIView categories UIView+TXWatermark;
[0069] S620 provides the addWaterMark instance method to external systems.
[0070] S630, call addWaterMark, and perform the following processing steps S631 to S635 through addWaterMark:
[0071] S631, obtain the input parameters;
[0072] S632, create a concurrent queue ConcurrentQueue;
[0073] S633, enable asynchronous threads;
[0074] S634, calculate the size of a single watermark (textSize) and the total number of lines and columns for displaying the watermark based on the input parameters;
[0075] S635 creates two loops: the outer loop iterates from the 0th iteration to the lineth iteration, and the inner loop iterates from the 0th iteration to the rowth iteration, to draw multiple watermarks.
[0076] like Figure 7 As shown, a flowchart of drawing a single watermark is provided in one embodiment, including the following steps S701 to S705:
[0077] S701, Create a CATextLayer object layer to obtain and process the current layer context;
[0078] S702, get the resolution (scale) of the current display screen (mainScreen) and set it in the contentsScale property of the layer;
[0079] S703, set the layer's string property to a rich text property (NSAttributedString type), set the rich text's font, font size, line spacing, and other properties, and use it and the calculated textSize as the layer's frame to indicate the layer's addition position;
[0080] S704: After taking the remainder of the line and row values from the two-layer traversal, multiply by the preset text rotation angle, call CATransform3DMakeRotation and set it to the layer's transform property to indicate the layer's rotation angle.
[0081] S705 adds the layer by calling the addSublayer method in the current view's layer. Additionally, the isSave field can be used to determine whether the current view needs to be written to the album.
[0082] In the above embodiments, the method of extending watermark drawing by classification is not intrusive to existing classes and methods. The interface is highly encapsulated, and watermark drawing and addition can be completed by simply passing in the corresponding watermark from the outside, which is convenient for callers and improves the efficiency of watermark generation. It is compatible with receiving rich text, can achieve mixed text and image layout, and supports the diversity of watermarks. Asynchronous drawing is used, which will not affect the loading efficiency of existing business functions and provides a better user experience.
[0083] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps.
[0084] In one embodiment, such as Figure 8 As shown, a watermark generation device 800 is provided. This device can be a software module, a hardware module, or a combination of both as part of a computer device. Specifically, the device includes: an acquisition module 810 and a calling module 820, wherein:
[0085] The acquisition module 810 is used to respond to the watermark addition command and acquire the target image and watermark parameters corresponding to the watermark addition command.
[0086] Module 820 is called to invoke the watermark drawing interface. A watermark layer with rich text attributes is created through the watermark drawing interface. The watermark is drawn on the watermark layer based on the watermark parameters. The watermark layer with the drawn watermark is then added to the target image.
[0087] In one embodiment, the watermark drawing interface is constructed based on the classification of interface view classes.
[0088] In one embodiment, the acquisition module 810 is further configured to: acquire the category header file corresponding to the watermark addition instruction, wherein the category header file includes a method index; and acquire the method corresponding to the watermark drawing interface from the method list of the interface view class according to the method index.
[0089] In one embodiment, when calling the watermark drawing interface, creating a watermark layer with rich text attributes through the watermark drawing interface, drawing a watermark on the watermark layer based on watermark parameters, and adding the watermark layer with the drawn watermark to the target image, the calling module 820 is specifically used for: starting a sub-thread through the watermark drawing interface, the sub-thread executing asynchronously with the main thread; creating a watermark layer with rich text attributes through the sub-thread, drawing a watermark on the watermark layer based on watermark parameters, and adding the watermark layer with the drawn watermark to the target image.
[0090] In one embodiment, when calling module 820 to draw a watermark on a watermark layer based on watermark parameters, it is specifically used to: parse the watermark parameters to obtain the watermark content and watermark format; and draw the watermark content onto the watermark layer according to the watermark format.
[0091] In one embodiment, the calling module 820 is further configured to: determine the width and height of a single watermark based on the watermark content and watermark format through the watermark drawing interface, and determine the total number of rows and columns based on the width and height of the single watermark, the watermark spacing, and the width and height of the target image.
[0092] In one embodiment, when calling module 820 to create a watermark layer with rich text attributes through the watermark drawing interface, it is specifically used to: determine the number of watermarks based on the total number of rows and columns through the watermark drawing interface, and create a watermark layer with rich text attributes for the number of watermarks.
[0093] In one embodiment, when adding a watermark layer with a watermark drawn on it to a target image, the calling module 820 is specifically used to: for each watermark layer, determine the corresponding addition position of the watermark layer in the target image according to the row number and column number of the watermark layer, and add the watermark layer with the watermark drawn on it to the target image according to the addition position.
[0094] In one embodiment, the calling module 810 is further configured to determine the watermark rotation angle of each watermark layer; when the calling module 820 adds the watermark layer with the watermark drawn to the target image according to the addition position, it is specifically configured to: rotate the watermark layer with the watermark drawn based on the watermark rotation angle, and add the rotated watermark layer to the target image according to the addition position.
[0095] In one embodiment, when calling module 810 to determine the watermark rotation angle of the watermark layer, it is specifically used to: determine the sequence number of the watermark layer according to the row number and column number of the watermark layer; take the remainder of the sequence number of the watermark layer with respect to the total number of rows or columns; and determine the watermark rotation angle of the watermark layer according to the remainder obtained by taking the remainder and the preset rotation angle.
[0096] Specific limitations regarding the watermark generation device can be found in the limitations of the watermark generation method described above, and will not be repeated here. Each module in the aforementioned watermark generation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in a computer device, or stored in software in the memory of a computer device, so that the processor can call and execute the corresponding operations of each module.
[0097] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 9 As shown. The computer device 900 includes a processor 920, memory, and a network interface 930 connected via a system bus 910. The processor 920 of the computer device 900 provides computing and control capabilities. The memory of the computer device 900 includes a non-volatile storage medium 940 and internal memory 950. The non-volatile storage medium 940 stores an operating system 941, a computer program 942, and a database 943. The internal memory 950 provides an environment for the operation of the operating system 941 and the computer program 942 stored in the non-volatile storage medium 940. The network interface 930 of the computer device is used for communication with external terminals via a network connection. When the computer program 942 is executed by the processor 920, it implements a watermark generation method.
[0098] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10As shown. The computer device 1000 includes a processor 1020, a memory, a communication interface 1030, a display screen 1040, and an input device 1050 connected via a system bus 1010. The processor 1020 of the computer device 1000 provides computing and control capabilities. The memory of the computer device 1000 includes a non-volatile storage medium 1060 and internal memory 1070. The non-volatile storage medium 1060 stores an operating system 1061 and a computer program 1062. The internal memory 1070 provides an environment for the operation of the operating system 1061 and the computer program 1062 stored in the non-volatile storage medium 1060. The communication interface 1030 of the computer device 1000 is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. When the computer program 1062 is executed by the processor 1020, it implements a watermark generation method. The display screen 1040 of the computer device 1000 can be an LCD screen or an e-ink screen. The input device 1050 of the computer device 1000 can be a touch layer covering the display screen 1040, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0099] Those skilled in the art will understand that Figure 9 or Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0100] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0101] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0102] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the steps in the above method embodiments.
[0103] It should be understood that the terms "first," "second," etc., used in the above embodiments are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means at least two.
[0104] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0105] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0106] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A method for generating a watermark, characterized in that, The method includes: In response to a watermark addition command, the target image and watermark parameters corresponding to the watermark addition command are obtained; Using the watermark drawing interface, the width and height of a single watermark are determined based on the watermark content and format obtained from the watermark parameters. The total number of rows and columns are then determined based on the width and height of the single watermark, the watermark spacing, and the width and height of the target image. The number of watermarks is determined based on the total number of rows and columns using the watermark drawing interface, and a watermark layer with rich text attributes for the number of watermarks is created. Call the watermark drawing interface to draw the watermark on each watermark layer based on the watermark parameters; For each watermark layer, the sequence number of the watermark layer is determined according to the row number and column number of the watermark layer. The sequence number of the watermark layer is then moduloed by the total number of rows or columns. The watermark rotation angle of the watermark layer is determined according to the remainder obtained by the modulo operation and a preset rotation angle. The watermark rotation angle refers to the angle of the watermark relative to the horizontal or vertical direction when it is added to the target image. Rotate each watermark layer according to its corresponding watermark rotation angle; For each watermark layer, the addition position of the watermark layer in the target image is determined according to the row number and column number of the watermark layer; the addition position of each watermark layer is different. The rotated watermark layer is added to the target image according to the specified addition position.
2. The method according to claim 1, characterized in that, The watermark drawing interface is constructed based on the classification of interface view classes.
3. The method according to claim 2, characterized in that, Before calling the watermark drawing interface, the following is also included: Obtain the category header file corresponding to the watermark addition instruction, wherein the category header file includes a method index; Based on the method index, the method corresponding to the watermark drawing interface is obtained from the method list of the interface view class.
4. The method according to any one of claims 1 to 3, characterized in that, The process of creating a watermark layer with rich text attributes through the watermark drawing interface, drawing a watermark on the watermark layer based on the watermark parameters, and adding the watermarked watermark layer to the target image includes: A sub-thread is started through the watermark drawing interface, and the sub-thread executes asynchronously with the main thread. A watermark layer with rich text attributes is created through the sub-thread, a watermark is drawn on the watermark layer based on the watermark parameters, and the watermark layer with the drawn watermark is added to the target image.
5. The method according to any one of claims 1 to 3, characterized in that, Drawing the watermark on the watermark layer based on the watermark parameters includes: The watermark parameters are parsed to obtain the watermark content and watermark format; The watermark content is drawn onto the watermark layer according to the watermark format.
6. A watermark generation device, characterized in that, The device includes: The acquisition module is used to acquire the target image and watermark parameters corresponding to the watermark addition command in response to the watermark addition command; The calling module is used to determine the width and height of a single watermark based on the watermark content and format parsed from the watermark parameters through the watermark drawing interface; determine the total number of rows and columns based on the width and height of the single watermark, the watermark spacing, and the width and height of the target image; determine the number of watermarks based on the total number of rows and columns through the watermark drawing interface; create a watermark layer with rich text attributes for the specified number of watermarks; call the watermark drawing interface to draw watermarks on each watermark layer based on the watermark parameters; for each watermark layer, determine the corresponding sequence number of the watermark layer based on the row and column numbers, and determine the corresponding watermark rotation angle based on the sequence number of the watermark layer; the watermark rotation angle refers to the angle relative to the horizontal or vertical direction when the watermark is added to the target image; rotate each watermark layer with a drawn watermark according to its corresponding watermark rotation angle, and add the rotated watermark layers to the target image.
7. The apparatus according to claim 6, characterized in that, The watermark drawing interface is constructed based on the classification of interface view classes.
8. The apparatus according to claim 7, characterized in that, The acquisition module is further configured to: acquire the category header file corresponding to the watermark addition instruction, wherein the category header file includes a device index; and acquire the device corresponding to the watermark drawing interface from the device list of the interface view class according to the device index.
9. The apparatus according to any one of claims 6 to 8, characterized in that, The calling module is also used to: start a sub-thread through the watermark drawing interface, the sub-thread being executed asynchronously with the main thread; create a watermark layer with rich text attributes through the sub-thread; draw a watermark on the watermark layer based on the watermark parameters; and add the watermark layer with the drawn watermark to the target image.
10. The apparatus according to any one of claims 6 to 8, characterized in that, The calling module is also used to: parse the watermark parameters to obtain the watermark content and watermark format; and draw the watermark content onto the watermark layer according to the watermark format.
11. A computer device, characterized in that, The method includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method as described in any one of claims 1 to 5.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5.
13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5.