Watermark image generation method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202210483728.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-05
- Publication Date
- 2026-10-13
- Estimated Expiration
- 2042-05-05
AI Technical Summary
但通常拍摄软件提供的水印样式,对于用户而言选择空间较少,而对于开发人员而言,对提供的水印样式进行修改时较为困难
[0008]本申请提供的方案,通过获取待处理图像;获取处于开启状态的水印功能开关所对应的水印基础视图;基于水印视图框组件,以及所述水印基础视图,生成包含所述水印基础视图的位图,所述水印视图框组件包括所述水印基础视图的布局参数;将所述位图绘制于所述待处理图像中,得到水印图像。由此,由于在生成水印图像的过程中,电子设备通过继承于所有水印基础视图的水印视图框组件及其对应的布局参数,生成包含水印基础视图对应的位图,因此需要修改水印样式时,对水印视图框组件中的布局参数进行修改,即可实现对水印样式的修改,从而使水印样式的修改更加方便。
Smart Images

Figure CN117057967B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing, and more specifically, to a method, apparatus, electronic device, and storage medium for generating a watermarked image. Background Technology
[0002] With the widespread use of mobile phones and other electronic devices, people have become accustomed to taking photos of their daily lives as keepsakes, and many users habitually add unique watermarks to their photos to highlight their personal style. However, the watermark styles provided by photography software typically offer limited choices for users, and modifying these styles can be quite difficult for developers. Summary of the Invention
[0003] This application proposes a method, apparatus, electronic device, and storage medium for generating watermarked images to enhance the configurability of watermark styles.
[0004] In a first aspect, embodiments of this application provide a method for generating a watermarked image, the method comprising: acquiring an image to be processed; acquiring a watermark base view corresponding to a watermark function switch that is in an on state; generating a bitmap containing the watermark base view based on a watermark view frame component and the watermark base view, wherein the watermark view frame component includes layout parameters of the watermark base view; and drawing the bitmap onto the image to be processed to obtain a watermarked image.
[0005] Secondly, embodiments of this application provide a watermark image generation apparatus, the apparatus comprising: an image acquisition module, a basic view generation module, a bitmap generation module, and an image generation module, wherein the image acquisition module is used to acquire an image to be processed; the basic view generation module is used to acquire a watermark basic view corresponding to a watermark function switch that is in an on state; the bitmap generation module is used to generate a bitmap containing the watermark basic view based on a watermark view frame component and the watermark basic view, the watermark view frame component including layout parameters of the watermark basic view; and the image generation module is used to draw the bitmap onto the image to be processed to obtain a watermark image.
[0006] Thirdly, embodiments of this application provide an electronic device, including: one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more application programs are configured to perform the watermark image generation method provided in the first aspect above.
[0007] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code that can be called by a processor to execute the watermark image generation method provided in the first aspect above.
[0008] The solution provided in this application involves: acquiring an image to be processed; acquiring a watermark base view corresponding to a watermark function switch that is in the "on" state; generating a bitmap containing the watermark base view based on a watermark view frame component and the watermark base view, wherein the watermark view frame component includes layout parameters of the watermark base view; and drawing the bitmap onto the image to be processed to obtain a watermark image. Therefore, since the electronic device generates a bitmap containing the watermark base view by inheriting the watermark view frame component and its corresponding layout parameters from all watermark base views during the watermark image generation process, modifying the layout parameters in the watermark view frame component is sufficient to modify the watermark style, making watermark style modification more convenient. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A flowchart illustrating a method for generating a watermarked image according to an embodiment of this application is shown.
[0011] Figure 2 A flowchart illustrating a method for generating a watermarked image according to another embodiment of this application is shown.
[0012] Figure 3 A flowchart illustrating a method for generating a watermarked image according to another embodiment of this application is shown.
[0013] Figure 4 A schematic diagram of the specific process of step S310 in another embodiment of this application is shown.
[0014] Figure 5 A schematic diagram of the structure of a watermark view frame component is shown in yet another embodiment of this application.
[0015] Figure 6 A structural block diagram of the watermark image generation apparatus provided in an embodiment of this application is shown.
[0016] Figure 7 A structural block diagram of an electronic device provided in an embodiment of this application is shown.
[0017] Figure 8 A structural block diagram of a computer-readable storage medium provided in an embodiment of this application is shown. Detailed Implementation
[0018] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0019] Currently, everyone can take photos of their daily lives using their mobile phones, tablets, and other electronic devices, and the technology for processing these photos is becoming increasingly sophisticated. For some photographs, photographers often want to add their own personal watermarks. Therefore, many devices have begun to allow users to customize the watermark style in their images. For example, users can create unique watermarks by adjusting the on / off states of certain functions, which not only serve as anti-counterfeiting measures but also have a decorative effect.
[0020] In related technologies, watermark patterns are constructed from a bitmap. The size, pattern, and position of the bitmap are determined by whether the corresponding function switches for each element of the watermark pattern are enabled (e.g., for custom information, device name, geographic location, and date / time). Different drawing logic is then executed based on these parameters to draw the corresponding image or text. In this approach, the function switches directly affect the drawing function, causing coupling between the function switch logic and the drawing logic. This results in a fixed watermark style; adding new styles or even adjusting the relative positions of elements within the watermark pattern requires modifications to both the control and drawing logic.
[0021] To address the aforementioned problems, the inventors have proposed a method, apparatus, electronic device, and storage medium for generating watermarked images, as provided in the embodiments of this application. Since the electronic device generates a bitmap containing the watermark base view through a watermark view frame component that includes layout parameters of the watermark base view, modifying the layout parameters in the watermark view frame component allows for modification of the watermark style. The specific method for generating the watermarked image will be described in detail in subsequent embodiments.
[0022] The method for generating watermarked images provided in the embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0023] Please see Figure 1 , Figure 1 The diagram illustrates a flowchart of a watermark image generation method according to an embodiment of this application. The following will focus on... Figure 1The process shown is described in detail. The method for generating the watermark image may specifically include the following steps:
[0024] Step S110: Obtain the image to be processed.
[0025] In this embodiment, the electronic device can use the acquired input image as the image to be processed, which is the image to which a watermark pattern is to be added to generate a watermark image. As one possible implementation, the electronic device may include a camera. The electronic device can capture images through the camera and use the captured images as the image to be processed. For example, in a photo-taking scenario, after a user takes an image using the electronic device, they can use the electronic device to add a watermark pattern to it, thereby forming a watermark image. As another implementation, the electronic device can also obtain the image to be processed from locally stored images. These locally stored images can be images captured by the electronic device through the camera and stored in the local photo album, or images pre-downloaded from the network and stored in the local photo album. Of course, the specific method by which the electronic device obtains the image to be processed is not limited.
[0026] Step S120: Obtain the watermark base view corresponding to the watermark function switch that is in the on state.
[0027] In this embodiment, the watermark pattern added to the image to be processed by the electronic device can consist of multiple watermark contents, each corresponding to a watermark base view. Each watermark base view is used to present its corresponding watermark content. For example, the watermark pattern may include the generation time of the image to be processed, the location where the image was taken, the last modification time, and the name information of the electronic device that took the image. The generation time, location, last modification time, and name information can each correspond to a watermark base view. The watermark base view can be a view created from the View hierarchy of the Android system for the content in the watermark pattern.
[0028] Additionally, watermark function switches can be set for each watermark base view. This allows users to add watermark patterns to images via electronic devices by controlling the watermark function switches corresponding to different watermark base views to be active, thus enabling the addition of different watermark patterns. When processing the image, the electronic device can identify the active watermark function switches from all available switches and retrieve the corresponding watermark base views.
[0029] For example, an electronic device can create an ImageView for image-type watermark base views, a TextView for text-type watermark base views, a DivideTextView for text with dividing lines, and a DrawableTextView for text with shadows, etc. Developers can create the specific types of watermark base views according to their actual needs; this is not limited here. After creating multiple different watermark base views, the electronic device can set a corresponding watermark function switch for each watermark base view. Based on the watermark function switch being active, the device can determine which watermark base view can be drawn within the watermark pattern.
[0030] In some implementations, the electronic device can draw watermark function switches corresponding to each watermark base view in a visual interface. The electronic device can control the watermark function switches to be in an on or off state based on the operation of the watermark function switches. Optionally, each watermark function switch corresponding to a different watermark base view can have a different name. This name can be a name set based on the watermark content corresponding to the watermark base view, so that the user can determine whether to turn on the watermark function switch corresponding to that watermark base view based on the name and their own needs.
[0031] Understandably, whether the watermark content corresponding to multiple watermark base views is drawn in the image to be processed can be controlled by the state of multiple watermark function switches operated by the user, so that the final bitmap can meet the user's needs. Each watermark function switch corresponds to one watermark base view. If the watermark function switch is on, the watermark content corresponding to the corresponding watermark base view can be added to the image to be processed when adding the watermark pattern. If the watermark function switch is off, the watermark content corresponding to the corresponding watermark base view will not be added to the image to be processed. When a user adds a watermark pattern to the image to be processed using an electronic device, they can control the corresponding watermark function switch to be on according to their needs. The electronic device can then obtain the watermark base view corresponding to each on watermark function switch, and add the watermark pattern to the image to be processed based on the watermark base view, thereby obtaining the watermarked image.
[0032] It is worth noting that at this time, the electronic device obtains the corresponding watermark base view based on the watermark function switch that is in the on state. This only determines the watermark base view that can be contained in the final generated watermark image, that is, the watermark base view that needs to be drawn. However, the electronic device cannot obtain the watermark pattern based solely on the watermark function switch. Instead, after determining the watermark base view, it obtains the watermark image based on the layout parameters in the watermark view frame component and each watermark base view.
[0033] Step S130: Based on the watermark view frame component and the watermark base view, generate a bitmap containing the watermark base view, wherein the watermark view frame component includes the layout parameters of the watermark base view.
[0034] In this embodiment, after obtaining the watermark base view corresponding to the watermark function switch in the "on" state, the electronic device can determine that these watermark base views are the watermark base views that will ultimately be drawn in the watermark image. After obtaining the watermark base views that can be drawn, the electronic device can generate a bitmap containing the watermark base views based on the watermark view box component and the watermark base views obtained above. Simultaneously, the electronic device can also create a watermark view box component (WatermarkBox) that inherits from all the watermark base views created by the electronic device. Thus, the electronic device can call the corresponding watermark base views through the WatermarkBox and the watermark base view corresponding to the watermark function switch in the "on" state, thereby obtaining the watermark pattern. It is understandable that in a typical view hierarchy, view box components (such as the usual ViewBox) inherit from base views. However, in this embodiment, a watermark view box component is created for drawing the watermark pattern, and the watermark base view box component inherits from the watermark base views corresponding to different watermark contents in the watermark pattern.
[0035] The watermark view frame component includes layout parameters for the watermark base view. These parameters can include the position and size of the watermark base view within the watermark pattern, the drawing order of the watermark base views, and the view parameters corresponding to the watermark base view (i.e., the parameters inherited from the watermark base view). In other words, the layout parameters can achieve the corresponding watermark style. Using the layout parameters in the watermark view frame component, a bitmap can be drawn, and the bitmap contains the watermark base view corresponding to the watermark function switch when it is enabled. Therefore, by generating a bitmap using the watermark view frame component, the watermark base view in the generated bitmap can conform to the layout parameters in the watermark view frame component, thus generating a bitmap with the corresponding style, i.e., a watermark pattern.
[0036] Understandably, when an electronic device generates a bitmap, it can determine all the necessary watermark base views and then draw them sequentially according to certain rules and order, ultimately forming a bitmap containing these watermark base views. Subsequent steps then yield the watermark image. The rules and order between the multiple watermark base views can be determined by the layout parameters included in the watermark view frame component. Furthermore, the layout parameters in the watermark frame view include not only the positional relationships between the watermark base views but also view parameters within each watermark base view that restrict its size, shape, and other information. This allows for the generation of a bitmap (watermark pattern) with a watermark style corresponding to the layout parameters. In some implementations, the relationship between the watermark view frame component and the aforementioned watermark base views can be that the watermark view frame component inherits from the watermark base views. That is, the watermark base view can inherit the view parameters from all its included watermark base views, and then, using the layout parameters in the watermark view frame component and the view parameters of the inherited watermark base views, it can draw the aforementioned watermark base views to generate the corresponding bitmap. Software developers can call and modify layout parameters based on the watermark view frame component to ensure that the watermark pattern obtained based on the layout parameters meets user requirements. Modification of layout parameters can include changes to the layout parameters within the watermark view frame component itself, as well as modifications to the view parameters in all base watermark views inherited by the watermark view frame component.
[0037] Step S140: Draw the bitmap onto the image to be processed to obtain a watermark image.
[0038] In this embodiment of the application, after the electronic device obtains a bitmap including a watermark base view, it can draw the bitmap onto the image to be processed to obtain a watermark image. At this time, the watermark image not only includes the image to be processed, but also includes the bitmap (i.e., the watermark pattern), thereby realizing the addition of the required watermark pattern to the image to be processed.
[0039] The watermark image generation method provided in this application involves: acquiring an image to be processed; acquiring a watermark base view corresponding to a watermark function switch that is in an on state; generating a bitmap containing the watermark base view based on a watermark view frame component and the watermark base view, wherein the watermark view frame component includes layout parameters of the watermark base view; and drawing the bitmap onto the image to be processed to obtain a watermark image. Therefore, since the electronic device generates a bitmap containing the watermark base view by inheriting the watermark view frame component and its corresponding layout parameters during the watermark image generation process, when it is necessary to modify the watermark style, the layout parameters of the watermark view frame component can be modified to achieve the modification of the watermark style, making it easier for users to modify the style of the watermark image.
[0040] Please see Figure 2 , Figure 2 This paper illustrates a flowchart of a watermark image generation method according to another embodiment of this application. The following will focus on... Figure 2 The process shown is described in detail. The method for generating the watermark image may specifically include the following steps:
[0041] Step S210: In response to the modification operation of the layout parameters, update the layout parameters in the watermark view frame component.
[0042] In this embodiment, before generating multiple watermark base views based on the watermark function switch, the electronic device can modify the layout parameters in the watermark view frame component in response to a modification operation on the layout parameters. The target parameters for modification can be user-inputted or pre-set parameters. Specifically, software developers can call and modify the view parameters corresponding to all the watermark base views contained within the watermark view frame component to meet user needs. They can also modify the internal parameters of the watermark view frame component that describe the positional relationships between all the watermark base views to adjust the arrangement order and size of the watermark content corresponding to the watermark base views in the watermark image.
[0043] Optionally, each watermark base view may include parameters describing the length and width of the corresponding watermark content, named width and height respectively. It may also include a first distance parameter LeftMargin describing the distance between the watermark base view and the adjacent left watermark base view, and a second distance parameter TopMargin describing the distance between the watermark base view and the adjacent top watermark base view. It may also include parameters such as Paint describing the brush type corresponding to the watermark base view. After the WatermarkBox component inherits from any watermark base view, developers can call the various parameters in the aforementioned watermark base view based on the WatermarkBox component and modify them according to actual needs. This allows for easier modification while achieving adjustments to the watermark pattern effect.
[0044] The layout parameters in the watermark view frame component include not only the view parameters inherited from the base watermark view, but also layout parameters describing the positional relationships between the base watermark views. For example, the watermark view frame component may include an orientation parameter `mOrientation` to describe the arrangement direction of its base watermark views, a list parameter `mViewList` to store the base watermark views corresponding to the watermark function switches that are enabled, and a position parameter `mGravity` to describe the position of the watermark content corresponding to each base watermark view within the watermark pattern. Developers can modify these layout parameters based on the watermark view frame component to adjust the positional relationship of the watermark content corresponding to the base watermark view within the watermark pattern, thereby adjusting the style of the watermark pattern.
[0045] Understandably, the watermark view frame component inherits from all watermark base views. Therefore, software developers can generate corresponding watermark patterns using the layout parameters of the watermark view frame component and all watermark base views. They can also modify the layout parameters in the watermark view frame component to change the style of the watermark pattern.
[0046] In some implementations, the electronic device can acquire user modifications to layout parameters and target parameters via interactive hardware. The device can then update the existing layout parameters to the user-input target parameters to ensure the final watermark image meets user requirements. As another possible implementation, after acquiring the user-input target parameters, the electronic device can further evaluate them. If the target parameters exceed a preset range, it indicates that a watermark image cannot be obtained based on those parameters, and an error message can be output to prompt the user to change the target parameters. In yet another possible implementation, if the user inputs a target parameter, the electronic device can output a corresponding preview image, allowing the user to visually understand the style of the watermark image generated based on the target parameters, thus facilitating modification of the target parameters.
[0047] In some implementations, the modification operation on the layout parameters in step S210 may also be the following steps:
[0048] When a new watermark base view is added, in response to a modification operation on the layout parameters, the layout parameters corresponding to the watermark base view are added to the layout parameters.
[0049] In this implementation, if none of the watermark base views in the watermark view frame component meet the user's requirements for watermark style, the electronic device can add corresponding watermark base views according to the user's actual needs. Software developers can set default values for each view parameter in the newly added watermark base view. Simultaneously, the electronic device can allow the watermark view frame component to inherit the newly added watermark base view and, in response to modifications to the layout parameters, add the view parameters corresponding to the watermark base view to the layout parameters. This enables software developers to call the view parameters corresponding to the newly added watermark base view based on the watermark view frame component to generate the corresponding watermark content, and to modify the corresponding view parameters to adjust the style of the watermark pattern.
[0050] For example, if the existing watermark viewbox component only has a TextView basic view for text watermarks and no image watermark basic view, the electronic device can add an ImageView basic view for image watermarks based on the user's requirements for image identifiers in the watermark image. Simultaneously, the multiple view parameters included in this ImageView basic view are set to default values. To make it easier for software developers to modify the view parameters of this newly added ImageWatermark basic view, the watermark viewbox component can inherit from the ImageWatermark basic view. Furthermore, the electronic device can respond to modifications to the layout parameters of the watermark viewbox component by adding view parameters corresponding to the ImageWatermark basic view to the layout parameters, allowing software developers to generate or modify the watermark content corresponding to the ImageWatermark basic view based on the layout parameters.
[0051] As one possible implementation, when adding a new watermark base view, the electronic device can also simultaneously add a watermark function switch corresponding to the new watermark base view on the user display interface, so that the user can determine whether to generate the corresponding watermark base view in the final watermark image based on the on / off state of the watermark function switch.
[0052] Step S220: Obtain the image to be processed.
[0053] Step S230: Obtain the watermark base view corresponding to the watermark function switch that is in the on state.
[0054] In the embodiments of this application, steps S220 and S230 can be referred to the contents of other embodiments, and will not be repeated here.
[0055] Step S240: Based on the direction parameters, add all the watermark base views to the view list in sequence.
[0056] In this embodiment, the layout parameters include a direction parameter describing the arrangement direction of the watermark base views, and a view list for storing the watermark base views to be drawn. Wherein, when the direction parameter is determined, that is, when the arrangement direction between all watermark base views is determined, the electronic device can obviously determine a sequential arrangement order for all watermark base views based on the determined arrangement direction. If all watermark base views are added to the view list based on this arrangement order, then when generating the watermark image, the electronic device can draw each watermark base view sequentially according to the arrangement order of the watermark base views in the view list, thereby obtaining a watermark pattern with the correct relative positions between the various watermark base views.
[0057] As one possible implementation, the direction parameter can include either horizontal or vertical orientation. When the direction parameter is determined, the electronic device can add all watermark base views to the view list sequentially based on the determined direction order. For example, if the direction parameter is horizontal, the electronic device can add all watermark base views to the view list sequentially from left to right. The reason for adding watermark base views from left to right is that the view parameters corresponding to each watermark base view include not only the font size and shape, but also the distance parameters between the watermark base view and its left-hand adjacent watermark base view, and its top-hand adjacent watermark base view. Therefore, based on these parameters, when the direction parameter in the layout parameters is horizontal, the electronic device adds each watermark base view in a left-to-right order; similarly, if the direction parameter is vertical, the electronic device can add each watermark base view in a top-to-bottom order. Obviously, if the view parameters in the watermark base view are the distance parameters between the watermark base view to the right and the watermark base view to the bottom, then the electronic device can also add each watermark base view in the order from right to left or from bottom to top.
[0058] Step S250: Based on the watermark view frame component after updating the view list and the watermark base view, generate a bitmap containing the watermark base view.
[0059] In this embodiment, the updated view list includes all watermark base views corresponding to the watermark function switches that are in the "on" state. These watermark base views are arranged in a specific order within the view list. Therefore, the electronic device can sequentially draw the watermark base views based on the arrangement order of the various watermark base views in the updated view list, thereby obtaining a bitmap containing the watermark base views. It is understood that the watermark view frame component includes not only a list parameter specifying the arrangement order of the watermark base views, but also other parameters to limit the positional relationships between the watermark base views, so that the final generated bitmap meets the user's requirements.
[0060] In some implementations, the layout parameters further include the size parameters of the watermark view frame component and the position parameters of the watermark base view. The method for generating a bitmap containing the watermark base view based on the watermark view frame component and the watermark base view in step S250 can be implemented in the following ways:
[0061] Based on the direction parameter, the size parameter, the position parameter, and the view parameters corresponding to all the watermark base views, the watermark base views added to the view list are drawn to obtain a bitmap containing the watermark base views.
[0062] In this implementation, the size parameter represents the length and width of the watermark view frame component, which is the length and width of the bitmap containing the watermark base view. The position parameter represents the position of each watermark base view within the watermark view frame component, such as being centered, at the bottom, or to the left. The electronic device generates a bitmap containing the watermark base views based on the watermark view frame component and the watermark base views. This is achieved by generating a bitmap containing the watermark base views based on the layout parameters (including orientation, size, and position parameters) of the watermark view frame component and the view parameters corresponding to the watermark base views, thus obtaining the watermark image. Since the watermark view frame component inherits from all watermark base views, software developers can use the watermark view frame component to call or modify the layout parameters and the view parameters corresponding to the watermark view component, allowing for the configuration of the view parameters of the watermark base views to ensure that the final generated watermark image meets user requirements.
[0063] In some implementations, the electronic device can determine the size parameters of the watermark view frame component based on the orientation parameters in the watermark view frame component and the view parameters corresponding to each watermark base view. For example, if the orientation parameter in the watermark view frame component is horizontal, it indicates that the watermark base views are arranged horizontally in the final generated bitmap. Therefore, the width of the bitmap is the maximum width among all watermark base views, and the length of the bitmap is the sum of the lengths of each watermark base view. Understandably, the view parameters corresponding to each watermark base view can include the length and width of that watermark base view. In other words, the electronic device can determine the size parameters based on the orientation parameters and the view parameters corresponding to each watermark base view.
[0064] In some implementations, the view parameters corresponding to each watermark base view may include parameters characterizing the length and width of the watermark base view. As one possible implementation, the parameters characterizing length and width in the view parameters may be greater than or equal to the actual length and width of the watermark base view after it is drawn. Understandably, if the parameter characterizing the length of the watermark base view is a first parameter, and the parameter characterizing the width of the watermark base view is a second parameter, and the view parameters may also include a first distance parameter characterizing the distance between the watermark base view and its left adjacent watermark base view, and a second distance parameter characterizing the distance between the watermark base view and its top adjacent watermark base view, then the magnitude of the first parameter in the view parameters corresponding to the watermark base view may be equal to the sum of the first distance parameter and the actual length of the watermark base view, and the magnitude of the second parameter may be equal to the sum of the second distance parameter and the actual width of the watermark base view. Therefore, the electronic device can determine the size parameters of the watermark view frame component based on the first and second parameters in the view parameters corresponding to each watermark base view. In other words, if the watermark base views included in the watermark view frame component are arranged horizontally, then the length of the watermark view frame component can be the sum of the first parameters of each of its included watermark base views, and the width of the watermark view frame component can be the sum of the second parameters of each of its included watermark base views.
[0065] Step S260: Based on the position parameters, draw the bitmap at the corresponding position in the image to be processed to obtain the watermark image.
[0066] In this embodiment, the layout parameters include positional parameters describing the watermark view frame component within the image to be processed. After generating a bitmap containing a watermark base view, the electronic device can draw the bitmap onto the image to be processed to obtain a watermarked image with the watermark identifier. The relative positional relationship between the bitmap and the image to be processed can be obtained through the positional parameters in the layout parameters corresponding to the watermark view frame component.
[0067] In some possible implementations, the position parameter may include fixed orientations such as top left, bottom left, center, top right, and bottom right. In other implementations, the position parameter may also be a position coordinate. For example, the electronic device may use the top left vertex of the image to be processed as the origin and establish a standard coordinate system, and then use the coordinate data of the top left vertex of the bitmap of the watermark base image in the standard coordinate system as the position parameter in the watermark view frame component.
[0068] The watermark image generation method provided in this application updates the layout parameters in the watermark view frame component in response to a modification operation on the layout parameters, obtains the watermark base view corresponding to the watermark function switch that is in the on state, adds all watermark base views to the view list sequentially based on the direction parameters, generates a bitmap containing the watermark base views based on the updated watermark view frame component and the watermark base views, and draws the bitmap on the image to be processed to obtain the watermark image. Since the bitmap is generated using the watermark view frame component inherited from the watermark base views, when the watermark style needs to be modified, the layout parameters in the watermark view frame component can change with the user's modification operation, thereby making the style of the final watermark image more in line with the user's needs.
[0069] Please see Figure 3 , Figure 3 This illustration shows a flowchart of a method for generating a watermarked image according to another embodiment of this application. The following will focus on... Figure 3 The process shown is described in detail. The method for generating the watermark image may specifically include the following steps:
[0070] Step S310: Based on the aggregation degree value between every two watermark base views in all watermark base views corresponding to all watermark function switches, at least one view container component is obtained, wherein the view container component includes the layout parameters of its corresponding watermark base view.
[0071] In this embodiment, the electronic device may include multiple different watermark base views, each of which can be used to represent different aspects of the image to be processed. Therefore, there may be high cohesion among multiple watermark base views. In this case, the electronic device can construct multiple highly cohesive watermark base views into a view container component to facilitate program encapsulation and use. The view container component then exhibits high robustness, high reliability, high reusability, and high understandability. Software developers can more easily call the view parameters in the watermark base views based on the view container component and the watermark view frame component, and can also easily modify and add watermark styles.
[0072] Understandably, the view container component inherits from all the watermark base views it includes. Therefore, the view container component also includes corresponding layout parameters to describe the relationships between all the watermark base views it includes. In some implementations, the view container component may also include orientation parameters, position parameters, size parameters, and list parameters, the meaning of which can be found in the description of the foregoing embodiments. All the watermark base views included in the view container component also have corresponding view parameters to define the watermark content corresponding to these watermark base views.
[0073] In some implementations, the electronic device obtains the aggregation value between various watermark base views by analyzing the source code to obtain a non-quantitative result, or by examining the text structure of the source code to obtain a quantified score of cohesion. As another possible implementation, the electronic device can also obtain the aggregation value between watermark base views based on the frequency of use of each watermark base view and the number of times they are related.
[0074] In some implementations, such as Figure 4 As shown, the method for constructing at least one view container component based on the aggregation degree value between every two watermark base views in step S310 can be implemented through the following steps:
[0075] Step S311: Obtain the aggregation degree value between every two watermark base views in all watermark base views.
[0076] In this implementation, the aggregation degree value characterizes the degree of cohesion between two watermark base views. Higher cohesion results in a higher aggregation degree value between the two watermark base views. If the electronic device constructs these two watermark base views into a view container component and configures the layout parameters corresponding to that component, software developers can reduce tedious configuration calls and modify bitmap styles more intuitively. Thus, the electronic device can obtain the aggregation degree value between every two watermark base views and determine the number of view container components to be constructed and the different watermark base views contained in each component based on the aggregation degree value.
[0077] Step S312: Cluster all watermark base views based on the aggregation degree value between each pair of watermark base views.
[0078] In this embodiment, after obtaining the aggregation degree value between any two watermark base views, the electronic device can determine the number of view container components and the watermark base views contained in each view container component through clustering. Specifically, if the aggregation degree value between two watermark base views is higher than a preset threshold, these two watermark base views can be grouped into one class. Subsequently, the aggregation degree value between the target watermark base view and each watermark base view in the class is obtained sequentially. If all of them are higher than the preset threshold, the target watermark base view is also included in the same class. After repeating this process several times, at least one view container component can be obtained.
[0079] Step S313: Based on the clustering results, construct a view container component from the watermark base views existing in the target category that have multiple watermark base views, wherein the aggregation degree value between any two watermark base views in the target category is greater than a preset threshold.
[0080] In this implementation, based on the clustering results, the aggregation degree value between all watermark base views in each cluster is higher than a certain value. On this basis, the watermark base views in each cluster are constructed into a view container component. This ensures that the aggregation degree value between any watermark base views in the obtained view container component is high, thereby effectively reducing the workload of software developers when modifying watermark style parameters.
[0081] Step S320: Based on the view container component and other watermark base views, obtain the watermark view frame component, wherein the other watermark base views are the watermark base views other than the watermark base view corresponding to the intermediate view frame component among all the watermark base views.
[0082] In the embodiments of this application, it is understood that after the electronic device constructs at least one view container component based on the aggregation degree values between various watermark base views, there may still be some watermark base views with low aggregation degree values between them and all other watermark base views. In this case, it is not possible to construct a view container component based on a single watermark base view. Therefore, the electronic device can use these single watermark base views as other watermark base views, and then obtain a watermark view frame component based on the view container component and other watermark base views. The watermark view frame component obtained at this time inherits from all view container components and other watermark base views. Therefore, software developers can call the layout parameters corresponding to the view container component and the view parameters corresponding to other watermark base views based on the watermark view frame component, so as to modify the layout parameters and view parameters according to actual needs and obtain a new style of watermark image.
[0083] For example, please see Figure 5 The WatermarkBox component comprises three different base watermark views: ImageView for image watermarks, TextView for text watermarks, and DivideTextView for divider text watermarks. When the electronic device examines the text structure of the source code and determines that the aggregation value between the TextView and DivideTextView watermark views exceeds a preset threshold, a TextBox container component is created, inheriting from both TextView and DivideTextView. The layout parameters for the TextBox are set, and the WatermarkBox inherits from both TextBox and the ImageView watermark view. The WatermarkBox can then draw the watermark pattern by calling the layout parameters of the TextBox and the view parameters of the ImageView.
[0084] Step S330: Obtain the image to be processed.
[0085] Step S340: Obtain the watermark base view corresponding to the watermark function switch that is in the on state.
[0086] Step S350: Based on the watermark view frame component and the watermark base view, generate a bitmap containing the watermark base view, wherein the watermark view frame component includes the layout parameters of the watermark base view.
[0087] Step S360: Draw the bitmap onto the image to be processed to obtain a watermark image.
[0088] In the embodiments of this application, steps S330 to S360 can be referred to the contents of other embodiments, and will not be repeated here.
[0089] The watermark image generation method provided in this application obtains the aggregation degree value between any two watermark base views, clusters all watermark base views based on the aggregation degree value, constructs a view container component from the target category containing multiple watermark base views, obtains at least one view container component, obtains a watermark view frame component based on the view container component and other watermark base views, and then generates a bitmap containing the watermark base views based on the watermark view frame component and the watermark base views. The bitmap is then drawn on the image to be processed to obtain the watermark image. By obtaining the view container component through the aggregation degree value, and the watermark view frame component based on the view container component and the watermark base views, software developers can directly call the view container frame component and the watermark base views within the watermark view frame component to obtain the watermark pattern. They can also customize the style of the watermark image through the layout parameters of the watermark view frame component, making the process of modifying and calling data more convenient and intuitive for users.
[0090] Please see Figure 6 This document illustrates a structural block diagram of a watermark image generation apparatus 200 provided in an embodiment of this application. The watermark image generation apparatus 200 includes: an image acquisition module 210, a basic view generation module 220, a bitmap generation module 230, and an image generation module 240. Specifically, the image acquisition module 210 acquires an image to be processed; the basic view generation module 220 acquires a watermark basic view corresponding to a watermark function switch that is in the enabled state; the bitmap generation module 230 generates a bitmap containing the watermark basic view based on a watermark view frame component and the watermark basic view, the watermark view frame component including layout parameters of the watermark basic view; and the image generation module 240 draws the bitmap onto the image to be processed to obtain the watermark image.
[0091] As one possible implementation, the layout parameters include direction parameters describing the arrangement direction of the watermark base views, and a view list for storing the watermark base views to be drawn. The bitmap generation module 230 includes a view adding unit and a bitmap generation unit. The view adding unit adds all watermark base views to the view list sequentially based on the direction parameters; the bitmap generation unit generates a bitmap containing the watermark base views based on the updated watermark view frame component and the watermark base views.
[0092] As one possible implementation, the layout parameters also include the size parameters of the watermark view frame component and the position parameters of the watermark base view. The bitmap generation unit is further configured to draw the watermark base views added to the view list based on the direction parameters, the size parameters, the position parameters, and the view parameters corresponding to all the watermark base views, to obtain a bitmap containing the watermark base views.
[0093] As one possible implementation, the layout parameters include positional parameters describing the location of the watermark view frame component within the image to be processed. The image generation module 240 is further configured to draw a bitmap at the corresponding location within the image to be processed, based on the positional parameters, to obtain a watermarked image.
[0094] As one possible implementation, the watermark image generation apparatus 200 further includes a parameter modification module for updating the layout parameters in the watermark view frame component in response to a modification operation on the layout parameters.
[0095] As one possible implementation, the parameter modification module is also used to add the layout parameters corresponding to the watermark base view to the layout parameters in response to the modification operation on the layout parameters when a new watermark base view is added.
[0096] As one possible implementation, the watermark image generation apparatus 200 further includes a view container acquisition module and a view frame acquisition module. The view container acquisition module is used to obtain at least one view container component based on the aggregation degree value between every two watermark base views corresponding to all watermark function switches. The view container component includes the layout parameters of its corresponding watermark base view. The view frame acquisition module is used to obtain a view frame component based on the view container component and other watermark base views, where the other watermark base views are all watermark base views except for the watermark base view corresponding to the intermediate view frame component.
[0097] As one possible implementation, the view container acquisition module is further configured to acquire the aggregation degree value between every two watermark base views in all watermark base views; cluster all watermark base views based on the aggregation degree value between every two watermark base views; and construct a view container component based on the clustering results for the watermark base views existing in the target category with multiple watermark base views, wherein the aggregation degree value between every two watermark base views in the target category is greater than a preset threshold.
[0098] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0099] In the several embodiments provided in this application, the coupling between modules can be electrical, mechanical, or other forms of coupling.
[0100] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0101] In summary, the watermark image generation method provided in this application involves: acquiring an image to be processed; acquiring a watermark base view corresponding to a watermark function switch that is in the "on" state; generating a bitmap containing the watermark base view based on a watermark view frame component and the watermark base view, wherein the watermark view frame component includes the layout parameters of the watermark base view; and drawing the bitmap onto the image to be processed to obtain a watermark image. By using multiple different watermark function switches, the composition of the watermark image can be customized, and a watermark image can be generated based on the watermark view frame component and the watermark base view, making it more convenient to modify the watermark style.
[0102] Please refer to Figure 7 This diagram illustrates a structural block diagram of an electronic device 100 provided in an embodiment of this application. The electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, wherein the one or more application programs may be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more programs are configured to perform the methods described in the foregoing method embodiments.
[0103] Processor 110 may include one or more processing cores. Processor 110 connects to various parts of the electronic device using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 120, and by calling data stored in memory 120. Optionally, processor 110 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 110 may integrate one or more of a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), and a modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 110 and may be implemented separately using a communication chip.
[0104] The memory 120 may include random access memory (RAM) or read-only memory (ROM). The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created during the use of the electronic device (such as phonebook data, audio and video data, chat log data, etc.).
[0105] Please refer to Figure 8 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 800 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0106] The computer-readable storage medium 800 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 800 has storage space for program code 810 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 810 may, for example, be compressed in a suitable form.
[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for generating a watermarked image, characterized in that, The method includes: Obtain the image to be processed; Get the basic view of the watermark corresponding to the watermark function switch that is turned on; Based on the aggregation degree value between every two watermark base views in all watermark base views corresponding to all watermark function switches, at least one view container component is obtained. The view container component includes the layout parameters of its corresponding watermark base view. The aggregation degree value is used to characterize the degree of cohesion between two watermark base views. Based on the view container component and other watermark base views, a watermark view frame component is obtained. The other watermark base views are watermark base views other than the watermark base view corresponding to the middle view frame component among all watermark base views. The middle view frame component is a view container component obtained based on the aggregation degree value. Based on the watermark view frame component and the watermark base view corresponding to the watermark function switch, a bitmap containing the watermark base view corresponding to the watermark function switch is generated. The watermark view frame component includes the layout parameters of the watermark base view corresponding to the watermark function switch. The bitmap is drawn onto the image to be processed to obtain a watermarked image.
2. The method according to claim 1, characterized in that, The layout parameters include orientation parameters for describing the arrangement direction of the watermark base views, and a view list for storing the watermark base views to be drawn. The step of generating a bitmap containing the watermark base view corresponding to the watermark function switch based on the watermark view frame component and the watermark base view corresponding to the watermark function switch includes: Based on the direction parameters, all the watermark base views are added to the view list in sequence; Based on the updated watermark view frame component and the watermark base view, a bitmap containing the watermark base view is generated.
3. The method according to claim 2, characterized in that, The layout parameters also include the size parameters of the watermark view frame component and the position parameters of the watermark base view. Generating a bitmap containing the watermark base view based on the updated watermark view frame component and the watermark base view in the view list includes: Based on the direction parameter, the size parameter, the position parameter, and the view parameters corresponding to all the watermark base views, the watermark base views added to the view list are drawn to obtain a bitmap containing the watermark base views.
4. The method according to claim 1, characterized in that, The layout parameters include parameters describing the position of the watermark view frame component in the image to be processed. The step of drawing the bitmap onto the image to be processed to obtain the watermark image includes: Based on the position parameters, the bitmap is drawn at the corresponding position in the image to be processed to obtain the watermark image.
5. The method according to any one of claims 1-4, characterized in that, Before generating a bitmap containing the watermark base view corresponding to the watermark function switch based on the watermark view frame component and the watermark base view corresponding to the watermark function switch, the method further includes: In response to a modification operation on the layout parameters, the layout parameters in the watermark view frame component are updated.
6. The method according to claim 5, characterized in that, The step of updating the layout parameters in the watermark view frame component in response to a modification operation on the layout parameters includes: When a new watermark base view is added, in response to a modification operation on the layout parameters, the layout parameters corresponding to the watermark base view are added to the layout parameters.
7. The method according to claim 1, characterized in that, The aggregation degree value between every two watermark base views corresponding to all watermark function switches is used to obtain at least one view container component, including: Obtain the aggregation degree value between every two watermark base views in all the watermark base views; Based on the aggregation degree value between every two watermark base views, all watermark base views are clustered; Based on the clustering results, the watermark base views existing in the target category with multiple watermark base views are constructed into a view container component, wherein the aggregation degree value between any two watermark base views in the target category is greater than a preset threshold.
8. An apparatus for generating a watermarked image, characterized in that, The device includes: an image acquisition module, a basic view generation module, a view container acquisition module, a view frame acquisition module, a bitmap generation module, and an image generation module, wherein... The image acquisition module is used to acquire the image to be processed; The basic view generation module is used to obtain the watermark basic view corresponding to the watermark function switch that is in the on state. The view container acquisition module is used to obtain at least one view container component based on the aggregation degree value between every two watermark base views in all watermark base views corresponding to all watermark function switches. The view container component includes the layout parameters of its corresponding watermark base view. The aggregation degree value is used to characterize the degree of cohesion between two watermark base views. The view frame acquisition module is used to obtain a watermark view frame component based on the view container component and other watermark base views. The other watermark base views are watermark base views other than the watermark base view corresponding to the intermediate view frame component among all watermark base views. The intermediate view frame component is a view container component obtained based on the aggregation degree value. The bitmap generation module is used to generate a bitmap containing the watermark base view corresponding to the watermark function switch based on the watermark view frame component and the watermark base view corresponding to the watermark function switch. The watermark view frame component includes the layout parameters of the watermark base view corresponding to the watermark function switch. The image generation module is used to draw the bitmap onto the image to be processed to obtain a watermarked image.
9. An electronic device, characterized in that, The electronic device includes: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications being configured to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code that can be invoked by a processor to execute the method as described in any one of claims 1-7.