Data storage method, device, electronic device and storage medium
By saving the pen shape and track point attributes of graffiti data, the problem of style changes when electronic devices save graffiti data is solved, and a user-friendly secondary editing experience is achieved.
Patent Information
- Application Number
- CN202210567682.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-23
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-05-23
AI Technical Summary
When electronic devices save user graffiti data, it is easy to change the data style, causing users inconvenience in subsequent editing and poor user experience.
Obtain the pen attributes (such as pen type, color, thickness) and track point attributes (such as coordinates) in the graffiti data, and save them to a file to facilitate secondary editing.
It achieves efficient and fast saving of graffiti data, improves the user's editing experience, and ensures the accuracy and editability of the data.
Smart Images

Figure CN114860094B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electronic devices, and more specifically, to a data storage method, device, electronic device and storage medium. Background Art
[0002] With the development of science and technology, electronic devices are used more and more widely and have more and more functions, becoming one of the necessities in people's daily life. At present, electronic devices gradually begin to support users to write or doodle directly. However, when electronic devices save user doodle data, there are obstacles to saving or the style of doodle data will be changed, which makes it inconvenient for users to perform secondary editing later and the user experience is not good. Summary of the invention
[0003] In view of the above problems, the present application proposes a data preservation method, device, electronic device and storage medium to solve the above problems.
[0004] In a first aspect, an embodiment of the present application provides a method for saving data, the method comprising: obtaining graffiti data in a drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points that constitute the graffiti data; based on the pen type attributes and the track point attributes, saving the graffiti data to a file.
[0005] In a second aspect, an embodiment of the present application provides a data storage device, the device comprising: a data acquisition module, used to acquire graffiti data during a drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of a pen type, a pen color, and a pen tip thickness, and the track point attributes include the coordinates of the track points that constitute the graffiti data; a data storage module, used to save the graffiti data to a file based on the pen type attributes and the track point attributes.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory is coupled to the processor, the memory stores instructions, and when the instructions are executed by the processor, the processor executes the above method.
[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored, and the program code can be called by a processor to execute the above method.
[0008] The data saving method, device, electronic device and storage medium provided in the embodiments of the present application obtain graffiti data in a drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data. Based on the pen type attributes and the track point attributes, the graffiti data is saved to a file, so that the graffiti data is saved by saving the pen type attributes and the track point attributes of the graffiti data, and the graffiti data can be saved efficiently and quickly to facilitate secondary editing by users, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0010] Figure 1 A schematic diagram showing a flow chart of a method for storing data provided by an embodiment of the present application;
[0011] Figure 2 A schematic diagram showing a flow chart of a method for storing data provided by an embodiment of the present application;
[0012] Figure 3 A schematic diagram showing a flow chart of a method for storing data provided by an embodiment of the present application;
[0013] Figure 4 A schematic diagram showing a flow chart of a method for storing data provided by an embodiment of the present application;
[0014] Figure 5 A data structure diagram of graffiti data provided in an embodiment of the present application is shown;
[0015] Figure 6 A schematic diagram showing a flow chart of a method for storing data provided by an embodiment of the present application;
[0016] Figure 7 A data structure diagram of graffiti data provided in an embodiment of the present application is shown;
[0017] Figure 8 A schematic diagram showing the data format of the extended data provided in an embodiment of the present application;
[0018] Fig. 9 A schematic diagram showing a flow chart of a method for storing data provided by an embodiment of the present application;
[0019] Fig.10 A module block diagram of a data storage device provided by an embodiment of the present application is shown;
[0020] Fig.11 A block diagram of an electronic device for executing a method for storing data according to an embodiment of the present application is shown;
[0021] Fig.12 A storage unit for storing or carrying a program code for implementing a method for storing data according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0023] Currently, electronic devices are gradually beginning to support users to directly write or doodle. For example, electronic devices are gradually supporting users to doodle on something similar to traditional paper. However, during the doodle process, if the user wishes to save the doodled data for secondary editing, the electronic device cannot support this, which makes it inconvenient for the user to perform secondary editing later, and the user experience is poor.
[0024] In view of the above problems, the inventor has discovered after long-term research and proposed the data saving method, device, electronic device and storage medium provided in the embodiments of the present application. The graffiti data can be saved efficiently and quickly by saving the pen type attributes and track point attributes of the graffiti data, so that the user can perform secondary editing and improve the user experience. The specific data saving method will be described in detail in the subsequent embodiments.
[0025] See also Figure 1 , Figure 1 The flowchart of the data saving method provided by an embodiment of the present application is shown. The method is used to save the graffiti data by saving the pen type attributes and track point attributes of the graffiti data, which can save the graffiti data efficiently and quickly, so that the user can perform secondary editing and improve the user experience. In a specific embodiment, the data saving method is applied to Fig.10 The data storage device 200 and the electronic device 100 equipped with the data storage device 200 are shown. Fig.11 ). The following will take an electronic device as an example to illustrate the specific process of this embodiment. Of course, it can be understood that the electronic device used in this embodiment may include a smart phone, a tablet computer, a wearable electronic device, etc., which is not limited here. Figure 1The process shown is described in detail, and the data storage method may specifically include the following steps:
[0026] Step S110: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0027] The rendering of the graffiti content depends on the type of pen. Different pen types selected by the user will result in different rendering effects. For example, the effect of a pencil (one type of pen) is very different from that of a marker (another type of pen). The color of the pen, the thickness of the pen tip and other properties will also affect the rendering effect. Therefore, the type of pen, the color of the pen and the thickness of the pen tip can be summarized as pen type attributes.
[0028] Among them, the user's drawing trajectory also has a great impact on the rendering result. For example, the result of a user drawing a circle is always different from that of a user drawing a straight line, or the result of a user drawing in the upper left corner of the canvas is different from that of a user drawing in the upper right corner. The difference mainly comes from the coordinates of the trajectory points that make up the graffiti data. Therefore, the coordinates of the trajectory points that make up the graffiti data can be summarized as trajectory point attributes.
[0029] During the drawing process, the electronic device can render and display the graffiti data according to the pen type attributes and the track point attributes, wherein the pen type attributes and the track point attributes can be all inputs for rendering the graffiti data. Therefore, in this embodiment, the graffiti data during the drawing process can be obtained, wherein the graffiti data can include the pen type attributes and the track point attributes.
[0030] In some implementations, the electronic device may acquire graffiti data during the drawing process in real time, may acquire graffiti data during the drawing process at preset time intervals, may acquire graffiti data during the drawing process at preset time points, may acquire graffiti data during the drawing process according to user operations, may acquire graffiti data during the drawing process according to other preset rules, etc., which are not limited here. Optionally, in this embodiment, graffiti data during the drawing process may be acquired in real time to improve the accuracy of the acquired graffiti data.
[0031] As an implementable manner, the electronic device may detect whether the user is drawing, wherein if it is detected that the user is drawing, the graffiti data in the drawing process may be obtained.
[0032] As another feasible method, the electronic device may detect whether the user is drawing, wherein, when it is detected that the user is drawing, it may detect whether the user instructs to record the graffiti data, wherein, when it is detected that the user instructs to record the graffiti data, the graffiti data during the drawing process may be obtained.
[0033] In some embodiments, when the electronic device detects that the user is drawing, the pen type attributes involved in the drawing may be detected. For example, during the drawing process, the pen type, pen color, and / or pen tip thickness of the pen used for drawing may be detected. For example, the electronic device may be pre-set with a plurality of pen type attribute selection controls, and the plurality of pen type attribute selection controls are used to select pen type attributes such as pen type, pen color, and pen tip thickness. Therefore, the electronic device may obtain the pen type attributes involved in the drawing process based on the selection operation of the plurality of pen type attribute selection controls.
[0034] In some embodiments, when the electronic device detects that the user is drawing, the properties of the track points involved in the drawing may be detected. For example, during the drawing process, the coordinates of the drawn track points may be detected, the drawing speed may be detected, etc., which are not limited here. For example, a coordinate system may be established with the center of the electronic device as the origin, or a coordinate system may be established with a corner of the electronic device as the origin. During the drawing process, the coordinates of the drawn track points in the coordinate system may be detected to obtain the track point properties during the drawing process.
[0035] Step S120: based on the pen type attributes and the track point attributes, save the graffiti data into a file.
[0036] In this embodiment, when the pen type attributes and track point attributes are obtained, the graffiti data can be saved to a file based on the pen type attributes and track point attributes. When the pen type attributes and track point attributes are obtained, the pen type attributes and track point attributes can be saved to a file. When the user needs secondary editing, the file is loaded, the pen type attributes and track point attributes are obtained, and the graffiti scene can be restored to continue writing or graffiti, thereby improving the user experience.
[0037] In some implementations, the electronic device may pre-create a file in the storage space for storing graffiti data. When the pen type attributes and the track point attributes are obtained, the graffiti data may be saved in the pre-created file based on the pen type attributes and the track point attributes.
[0038] As an implementable method, when the pen type attribute and the track point attribute are obtained, the graffiti data can be saved in a file in Json format. The Json format is relatively simple to read and write, which can facilitate the reading and writing of graffiti data.
[0039] As another feasible method, when the pen type attribute and the track point attribute are obtained, the graffiti data can be saved to a file in a binary format. Compared with the graffiti data in the Json format, the graffiti data in the binary format is faster to load and can obtain better performance in loading.
[0040] A data saving method provided by an embodiment of the present application obtains graffiti data in a drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points that constitute the graffiti data, and saves the graffiti data to a file based on the pen type attributes and the track point attributes, thereby saving the graffiti data by saving the pen type attributes and the track point attributes of the graffiti data, and can save the graffiti data efficiently and quickly, so that the user can perform secondary editing, thereby improving the user experience.
[0041] See also Figure 2 , Figure 2 The flowchart of the method for saving data provided by an embodiment of the present application is shown in FIG. In this embodiment, the graffiti data is composed of at least one stroke. Figure 2 The process shown is described in detail, and the data storage method may specifically include the following steps:
[0042] Step S210: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0043] For the detailed description of step S210, please refer to step S110, which will not be repeated here.
[0044] Step S220: Determine the pen type attribute corresponding to at least one stroke and the track point attribute corresponding to at least one stroke.
[0045] In this embodiment, the graffiti data is composed of at least one stroke. When the graffiti data is saved, the graffiti data can be saved in units of strokes.
[0046] In some embodiments, when graffiti data is obtained, the graffiti data may be divided into at least one stroke, and the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke may be determined. The pen type attributes corresponding to different strokes may be the same or different, and the track point attributes corresponding to different strokes may be different.
[0047] As an implementable manner, if the graffiti data consists of one stroke, the pen type attribute corresponding to the one stroke and the track point attribute corresponding to the one stroke may be determined.
[0048] As another feasible method, if the graffiti data is composed of multiple strokes, the pen type attributes corresponding to each of the multiple strokes and the track point attributes corresponding to each of the multiple strokes can be determined. For example, assuming that the graffiti data is composed of stroke 1, stroke 2, and stroke 3, the pen type attributes and track point attributes corresponding to stroke 1, the pen type attributes and track point attributes corresponding to stroke 2, and the pen type attributes and track point attributes corresponding to stroke 3 can be determined.
[0049] Step S230: based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke, saving the at least one stroke into the file.
[0050] In this embodiment, when the pen type attribute corresponding to at least one stroke and the trajectory point attribute corresponding to at least one stroke are obtained, at least one stroke can be saved to a file based on the pen type attribute corresponding to at least one stroke and the trajectory point attribute corresponding to at least one stroke, that is, the graffiti data is saved to a file in units of strokes.
[0051] As an implementable method, take the example that the graffiti data consists of stroke 1, stroke 2 and stroke 3. Then, when the pen type attribute and track point attribute corresponding to stroke 1, the pen type attribute and track point attribute corresponding to stroke 2, and the pen type attribute and track point attribute corresponding to stroke 3 are determined, stroke 1 can be saved to a file based on the pen type attribute and track point attribute corresponding to stroke 1, stroke 2 can be saved to a file based on the pen type attribute and track point attribute corresponding to stroke 2, and stroke 3 can be saved to a file based on the pen type attribute and track point attribute corresponding to stroke 3, thereby realizing saving the graffiti data to a file.
[0052] As a method, when the graffiti data is composed of multiple strokes, for the multiple strokes, saving the multiple strokes into a file may include: saving the multiple strokes into a file at the same time, or saving the multiple strokes into a file in sequence. If the multiple strokes are saved into a file in sequence, it may include: saving the multiple strokes into a file in sequence in a random order, saving the multiple strokes into a file in sequence from the beginning to the end of the stroke drawing time, saving the multiple strokes into a file in sequence according to the user's selection, etc., which are not limited here.
[0053] In some embodiments, when the graffiti data is composed of multiple strokes, for the multiple strokes, saving the multiple strokes into a file may include: saving the multiple strokes into the file in sequence according to the drawing time corresponding to each of the multiple strokes from the beginning to the end. As a way, when the graffiti data is divided into multiple strokes, the drawing time corresponding to each of the multiple strokes may be obtained respectively, and then the drawing time corresponding to each of the multiple strokes may be compared, so as to sort the multiple strokes in the order of the drawing time from the beginning to the end according to the comparison result, and then the multiple strokes may be saved into the file in sequence according to the sorting.
[0054] For example, the graffiti data consists of stroke 1, stroke 2 and stroke 3, and the drawing time of stroke 1 is earlier than the drawing time of stroke 2, and the drawing time of stroke 2 is earlier than the drawing time of stroke 3. Then, stroke 1 is saved to the file first, and when stroke 1 is saved, stroke 2 is saved to the file, and when stroke 2 is saved, stroke 3 is saved to the file.
[0055] The data saving method provided by an embodiment of the present application obtains graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data, determines the pen type attributes corresponding to at least one stroke, and the track point attributes corresponding to at least one stroke, and based on the pen type attributes corresponding to at least one stroke, and the track point attributes corresponding to at least one stroke, saves at least one stroke to a file. Compared to Figure 1 The data storage method shown in the figure, this embodiment also stores the graffiti data in units of strokes, which can improve the storage effect of the graffiti data.
[0056] See also Figure 3 , Figure 3 The flowchart of the method for saving data provided by an embodiment of the present application is shown in FIG. In this embodiment, the graffiti data is composed of at least one stroke. Figure 3 The process shown is described in detail, and the data storage method may specifically include the following steps:
[0057] Step S310: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0058] The specific description of step S310 can be found in step S110 , which will not be repeated here.
[0059] Step S320: Determine the pen type attribute corresponding to at least one stroke and the track point attribute corresponding to at least one stroke.
[0060] For the detailed description of step S320, please refer to step S220, which will not be repeated here.
[0061] Step S330: creating a file header corresponding to the graffiti data.
[0062] In this embodiment, when the graffiti data is saved, a file header of the graffiti data may be created, wherein the file header is used to identify the graffiti data, for example, the file header may be used to identify the version of the graffiti data, the length of the file, the position of the graffiti data in the file, etc., which is not limited here.
[0063] In some embodiments, the file header may include a version number, a file length, a starting position of the graffiti data in the file, an ending position of the graffiti data in the file, etc., which are not limited here. It can be understood that based on the file header, the starting position and the ending position of the graffiti data in the file can be determined, which can improve the reading efficiency and accuracy of the graffiti data.
[0064] Step S340: Based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke, the file header and the at least one stroke are saved into the file.
[0065] In this embodiment, after obtaining the pen type attribute corresponding to at least one stroke and the track point attribute corresponding to at least one stroke, and creating a file header, the file header and at least one stroke can be saved to the file based on the pen type attribute corresponding to at least one stroke and the track point attribute corresponding to at least one stroke. The saving position of the at least one stroke in the file is located after the saving position of the file header in the file.
[0066] An embodiment of the present application provides a method for saving data, which obtains graffiti data during the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points that constitute the graffiti data, determines the pen type attributes corresponding to at least one stroke, and the track point attributes corresponding to at least one stroke, creates a file header corresponding to the graffiti data, and based on the pen type attributes corresponding to at least one stroke and the track point attributes corresponding to at least one stroke, saves the file header and at least one stroke to a file. Compared to Figure 1 The data saving method shown in the figure, this embodiment also sets the stroke to be composed of a stroke head and a track point attribute, which can improve the saving and reading effects of the stroke.
[0067] See also Figure 4 , Figure 4 The flowchart of the method for saving data provided by an embodiment of the present application is shown in FIG. In this embodiment, the graffiti data is composed of at least one stroke. Figure 4 The process shown is described in detail, and the data storage method may specifically include the following steps:
[0068] Step S410: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0069] The specific description of step S410 can be found in step S110 , which will not be repeated here.
[0070] Step S420: Determine the pen type attribute corresponding to at least one stroke and the track point attribute corresponding to at least one stroke.
[0071] For the detailed description of step S420, please refer to step S220, which will not be repeated here.
[0072] Step S430: Acquire the track point attribute corresponding to the stroke and create a stroke head corresponding to the stroke, wherein the stroke head includes the pen type attribute corresponding to the stroke and the end position of the track point attribute in the file.
[0073] As a method, for each stroke in at least one stroke, the stroke may be composed of a stroke head and a track point attribute. Therefore, in this embodiment, for each stroke in the graffiti data, the track point attribute corresponding to the stroke may be obtained, and a stroke head corresponding to the stroke may be created, wherein the stroke head includes the pen type attribute corresponding to the stroke (the type of pen, the color of the pen and / or the thickness of the pen tip, etc.) and the end position of the track point attribute in the file.
[0074] In some embodiments, since the file header includes the starting position of the graffiti data in the file, the starting position of the graffiti data in the file can be determined as the starting position of the first stroke of at least one stroke in the file, and based on the starting position of the first stroke in the file and the length of the stroke head of the first stroke in the file (wherein the length of the stroke head in the file is fixed and known), the starting position of the trajectory point attribute of the first stroke in the file can be determined, and based on the starting position of the trajectory point attribute of the first stroke in the file and the end position of the trajectory point attribute of the first stroke in the file, the graffiti data can be accurately obtained from the file. The trajectory point attributes of the first stroke are read from the file; wherein, the end position of the trajectory point attributes of the first stroke in the file can be determined as the starting position of the second stroke in the file, based on the starting position of the second stroke in the file and the length of the stroke head of the second stroke in the file, the starting position of the trajectory point attributes of the second stroke in the file can be determined, based on the starting position of the trajectory point attributes of the second stroke in the file and the end position of the trajectory point attributes of the second stroke in the file, the trajectory point attributes of the second stroke can be accurately read from the file, and so on, the trajectory point attributes of all strokes can be read.
[0075] Step S440: based on the stroke head corresponding to the stroke and the trajectory point attribute corresponding to the stroke, save the stroke into the file.
[0076] In this embodiment, when the stroke head corresponding to the stroke and the trajectory point attribute corresponding to the stroke are obtained, the stroke can be saved in a file based on the stroke head corresponding to the stroke and the trajectory point attribute corresponding to the stroke, and the above steps can be repeated to save all the strokes of the graffiti data in the file. The saving position of the trajectory point attribute of the stroke in the file is located after the saving position of the stroke head of the stroke in the file.
[0077] Step S450: Based on the length of the trajectory points, determine the storage length of the coordinates of the trajectory points constituting the stroke in the file.
[0078] The trajectory point attributes of a stroke may include not only the coordinates of the trajectory points that constitute the stroke, but also other trajectory point parameters, for example, the trajectory point speed. Therefore, it is also possible to set the trajectory point length of the corresponding stroke to be included in the stroke head, so as to read different trajectory point attributes from the file through the trajectory point length, for example, the coordinates of the trajectory point of the stroke are read from the file through the trajectory point length.
[0079] As a method, the track point length may refer to the length of the actual track corresponding to the stroke. For example, the track point length refers to the length of the stroke in the coordinate system. The storage length corresponding to the track point length in the file can be calculated by conversion. For example, the storage length occupied by a length unit (such as two bytes) can be pre-set. Then, when the track point length is obtained, the number of length units included in the track point length can be determined. Based on the number of length units included in the track point length and the storage length occupied by each length unit, the storage length of the coordinates of the track points constituting the stroke in the file can be determined. Therefore, when the track point length is obtained, the storage length of the coordinates of the track points constituting the stroke in the file can be determined based on the track point length.
[0080] Step S460: Based on the stored length, read the coordinates of the trajectory points of the stroke from the file.
[0081] In this embodiment, when the storage length of the coordinates of the trajectory points constituting the stroke in the file is determined, the coordinates of the trajectory points of the stroke can be read from the file based on the storage length. In some embodiments, it is assumed that the trajectory point attributes include the coordinates of the trajectory points constituting the stroke and the trajectory point speed. Then, when reading the file, the coordinates of the trajectory points of the stroke can be read according to the starting position of the trajectory point attributes of the stroke in the file, the trajectory point length, and the storage length (size) of the single trajectory point coordinate data, and then the trajectory point speed of the stroke can be read according to the trajectory point length and the storage length (size) of the single trajectory point speed data.
[0082] See also Figure 5 , Figure 5 A data structure diagram of graffiti data provided by an embodiment of the present application is shown. Figure 5 As shown, the data structure includes file header, stroke 1, stroke 2, stroke 3...stroke N, where the file header includes version number, file length, and the starting position of the graffiti data in the file. The stroke consists of a stroke head and track point attributes, and the stroke head includes pen type attributes, track point length, etc.
[0083] An embodiment of the present application provides a method for saving data, which obtains graffiti data in a drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points that constitute the graffiti data, determines the pen type attributes corresponding to at least one stroke, and the track point attributes corresponding to at least one stroke, obtains the track point attributes corresponding to the stroke and creates a stroke head corresponding to the stroke, wherein the stroke head includes the end position of the pen type attributes and the track point attributes corresponding to the stroke in a file, saves the stroke to a file based on the stroke head corresponding to the stroke and the track point attributes corresponding to the stroke, determines the storage length of the coordinates of the track points that constitute the stroke in the file based on the track point length, and reads the coordinates of the track points of the stroke from the file based on the storage length. Compared to Figure 1 In the data saving method shown in the figure, the present embodiment further sets the stroke to be composed of a stroke head and a track point attribute, so that by recording the end position of the stroke's pen type attribute and the track point attribute in the file in the stroke head corresponding to the stroke, the position of each data of the stroke in the file can be accurately located, which can improve the saving effect and reading effect of the stroke. In addition, the present embodiment further sets the stroke head to include the track point length, and reads the coordinates of the stroke's track point from the file based on the track point length, which can improve the accuracy of the stroke reading.
[0084] See also Figure 6 , Figure 6 The flowchart of the method for saving data provided by an embodiment of the present application is shown in FIG. In this embodiment, the graffiti data is composed of at least one stroke. Figure 6 The process shown is described in detail, and the data storage method may specifically include the following steps:
[0085] Step S510: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0086] For the detailed description of step S510, please refer to step S110, which will not be repeated here.
[0087] Step S520: Determine the pen type attribute corresponding to at least one stroke and the track point attribute corresponding to at least one stroke.
[0088] For the detailed description of step S520, please refer to step S220, which will not be repeated here.
[0089] Step S530: Based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke, save the at least one stroke into the file.
[0090] For the detailed description of step S530, please refer to step S230, which will not be repeated here.
[0091] Step S540: Acquire extended data.
[0092] Among them, with the continuous improvement of the graffiti function, in addition to drawing, the electronic device of this embodiment also gradually supports the function of editing existing graffiti data. For example, in terms of stroke attributes, some strokes in the graffiti data are selected for translation. Furthermore, the electronic device of this embodiment also gradually supports the function of optimizing existing graffiti data. For example, in terms of trajectory point attributes, when drawing with a marker, the larger the inclination angle, the thicker the corresponding stroke; when drawing with a brush, the greater the force, the thicker the corresponding stroke and the darker the color. Therefore, when drawing with a stylus, the thickness, color, etc. of the pen can be dynamically changed according to the pressure sensitivity of the stylus during drawing and the inclination angle data. In addition, in terms of file attributes, the electronic device of this embodiment also gradually supports the addition of file attributes to obtain some data without parsing all data files.
[0093] Based on this, the above functions can be divided into the following three categories:
[0094] First, for the file extension, based on the attributes of a single file, the same file has only one attribute. Some attributes are not related to a single stroke, but represent the relevant attributes of the file where the graffiti data is located, for example, recording the information of the current graffiti area.
[0095] Second, for the extension of stroke attributes, based on the attributes of a single stroke, different strokes in the same file have different attributes. Many operations are performed in units of strokes. For example, the translation of a stroke, after a translation operation, the translation amount of all trajectory points on the current stroke is the same, so it is sufficient to record the MVP matrix that can represent the translation of the stroke in the stroke header.
[0096] Third, for the extension of track point attributes, based on the attributes of a single track point, different track points have different attributes in the same stroke. The force changes when graffiti, and the pressure data of the stylus is for a single track point. Each track point should have its own pressure data. The attributes such as tilt angle are also the same.
[0097] After adding the above-mentioned extended data, the problem is that the higher version extends the file's saving attributes, but when the lower version opens the file, the lower version cannot recognize the extended data, which will cause abnormal file loading and loss of extended data, resulting in incompatibility between the higher and lower versions. In this embodiment, in order to solve the problem of data compatibility between the higher and lower versions, this embodiment can adaptively save the extended data.
[0098] In some implementations, extended data may be obtained, wherein the extended data may include data extending track point attributes, data extending stroke attributes, data extending files, etc., which are not limited here.
[0099] Step S550: saving the extended data based on the extended object corresponding to the extended data.
[0100] In this embodiment, when the extended data is obtained, the extended object corresponding to the extended data may be obtained, and the extended data may be saved based on the extended object corresponding to the extended data.
[0101] As a method, when obtaining extended data, the extended object corresponding to the extended data can be obtained. If the extended object corresponding to the extended data is the trajectory point attribute of the stroke, for example, if the extended data is pressure sensitivity data, tilt angle data, etc., the extended data can be used as a trajectory point attribute extension and the extended data can be saved to the end of the stroke in the file.
[0102] As another way, when obtaining extended data, the extended object corresponding to the extended data can be obtained. If the extended object corresponding to the extended data is the stroke attribute of the stroke, for example, if the extended data is translation data, the extended data can be used as a stroke data extension and saved to the end of the stroke in the file.
[0103] As another way, when obtaining extended data, the extended object corresponding to the extended data can be obtained. If the extended object corresponding to the extended data is a file, for example, if the extended data is information about the area range of graffiti, the extended data can be used as a file extension and saved to the end of the file.
[0104] See also Figure 7 , Figure 7 A data structure diagram of graffiti data provided by an embodiment of the present application is shown. Figure 7As shown, the data structure includes a file header, stroke 1, stroke 2, stroke 3, stroke N, and file extension, wherein the file header includes a version number, file length, and the starting position of the graffiti data in the file, etc. The stroke includes a stroke head, track point attributes, track point attribute extension, and stroke attribute extension, and the stroke head includes a pen type attribute, track point length, etc.
[0105] In some implementations, in order to use a unified data format to store extended data, it can be set as follows Figure 8 As shown in the figure, key represents the content of the extended data. Different enumeration values are defined in the program to represent different data contents. For example, key equals 0, which can represent pressure sensitivity, key equals 1, which can represent the tilt angle, etc. size represents the length of the extended data, which determines how many bytes of content will be read. Taking the tilt angle as an example, if a stroke has 1000 track points, and the tilt angle data of each track point occupies 4 bytes, then the size is 4000. When loading data, 4000 bytes of content will be read into the memory at one time and used as the tilt angle data. data represents the data itself, for example, the tilt angle data of 1000 track points.
[0106] In higher versions, the corresponding extended data will be parsed according to the key and applied in the program. For example, in the example of the tilt angle above. However, in lower versions, the key read out may be an undefined value. But it doesn't matter. You just need to read the data into the memory according to the size, and save the extended data in the memory into the file when saving the data. This ensures that the data is loaded and saved between higher and lower versions without loss, and achieves data backward compatibility.
[0107] In addition, in lower versions, unrecognizable extended data can also be modified. Among them, the track point attribute data may be modified. For example, in lower versions, partial erasure of strokes will discard some track points, and the corresponding track point attributes should be lost, whether it is the track point coordinate attributes that can be recognized by lower versions, or the pressure sensitivity, tilt angle and other data that cannot be recognized.
[0108] An embodiment of the present application provides a method for saving data, which obtains graffiti data during the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points that constitute the graffiti data, determines the pen type attributes corresponding to at least one stroke, and the track point attributes corresponding to at least one stroke, saves at least one stroke to a file based on the pen type attributes corresponding to at least one stroke and the track point attributes corresponding to at least one stroke, obtains extended data, and saves the extended data based on the extended object corresponding to the extended data. Compared to Figure 1 The data saving method shown in the figure, in this embodiment, when there is extended data, saves the extended data based on the extended object corresponding to the extended data, which can improve the applicability of the file in high and low versions.
[0109] See also Fig. 9 , Fig. 9 The following is a flow chart of a method for storing data provided by an embodiment of the present application. Fig. 9 The process shown is described in detail, and the data storage method may specifically include the following steps:
[0110] Step S610: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0111] Step S620: based on the pen type attributes and the track point attributes, save the graffiti data into a file.
[0112] For the detailed description of step S610 to step S620, please refer to step S110 to step S120, which will not be repeated here.
[0113] Step S630: In response to a display instruction for the graffiti data, acquiring the pen type attribute and the track point attribute from the file.
[0114] In this embodiment, after the graffiti data is saved to a file, it can be detected whether a display instruction for the graffiti data is received, wherein the display instruction is used to instruct the electronic device to display the graffiti data saved to the file. When an edit instruction for the graffiti data is received, the file can be loaded in response to the display instruction for the graffiti data, and the pen type attributes and trajectory point attributes of the graffiti data can be obtained from the file.
[0115] Step S640: based on the pen type attributes and the track point attributes, restore and display the graffiti data.
[0116] In this embodiment, when the pen type attributes and the track point attributes are obtained, the graffiti data can be restored and displayed based on the pen type attributes and the track point attributes, so that the user can perform secondary editing on the graffiti data.
[0117] The data saving method provided by an embodiment of the present application obtains graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data, and based on the pen type attributes and the track point attributes, the graffiti data is saved to a file, and in response to a display instruction for the graffiti data, the pen type attributes and the track point attributes are obtained from the file, and based on the pen type attributes and the track point attributes, the graffiti data is restored and displayed. Compared to Figure 1 The data saving method shown in the figure, in this embodiment, when the graffiti data needs to be edited again, the file is loaded to obtain the pen type attribute and the track point attribute, the graffiti scene can be restored, and writing or graffiti can be continued, which can improve the editing effect of the graffiti.
[0118] See also Fig.10 , Fig.10 The module block diagram of the data storage device provided by an embodiment of the present application is shown. Fig.10 The data storage device 200 includes: a data acquisition module 210 and a data storage module 220, wherein:
[0119] The data acquisition module 210 is used to acquire graffiti data during the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data.
[0120] The data saving module 220 is used to save the graffiti data into a file based on the pen type attribute and the track point attribute.
[0121] Furthermore, the graffiti data is composed of at least one stroke, and the data storage module 220 includes: an attribute acquisition submodule and a first data storage submodule, wherein:
[0122] The attribute acquisition submodule is used to determine the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke.
[0123] The first data saving submodule is used to save the at least one stroke into the file based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke.
[0124] Furthermore, the graffiti data is composed of a plurality of strokes, and the data storage submodule comprises: a first data storage unit, wherein:
[0125] The first data saving unit is used to save the multiple strokes into the file in sequence according to the drawing time corresponding to each of the multiple strokes from front to back.
[0126] Furthermore, the first data storage submodule includes: a file header creation unit and a first data storage unit, wherein:
[0127] The file header creation unit is used to create a file header corresponding to the graffiti data.
[0128] The first data storage unit is used to save the file header and the at least one stroke into the file based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke.
[0129] Further, for each stroke of at least one stroke, the data storage submodule includes: a stroke head creation unit and a second data storage unit, wherein:
[0130] The stroke head creation unit is used to obtain the track point attribute corresponding to the stroke and create a stroke head corresponding to the stroke, wherein the stroke head includes the pen type attribute corresponding to the stroke and the end position of the track point attribute in the file.
[0131] The second data storage unit is used to save the stroke into the file based on the stroke head corresponding to the stroke and the trajectory point attribute corresponding to the stroke.
[0132] Furthermore, the data storage submodule includes: a storage length determination unit and a coordinate determination unit, wherein:
[0133] The storage length determination unit is used to determine the storage length of the coordinates of the trajectory points constituting the stroke in the file based on the trajectory point length.
[0134] A coordinate determination unit is used to read the coordinates of the trajectory points of the stroke from the file based on the storage length.
[0135] Furthermore, the data storage submodule includes: an extended data acquisition unit and an extended data storage unit, wherein:
[0136] The extended data acquisition unit is used to acquire extended data.
[0137] The extended data storage unit is used to store the extended data based on the extended object corresponding to the extended data.
[0138] Further, the extended data storage unit includes: a first extended data storage subunit, a second extended data storage subunit and a third extended data storage subunit, wherein:
[0139] The first extended data saving subunit is used for saving the extended data after the stroke in the file if the extended object corresponding to the extended data is the trajectory point attribute of the stroke.
[0140] The second extended data saving subunit is used for saving the extended data after the stroke in the file if the extended object corresponding to the extended data is the stroke attribute of the stroke.
[0141] The third extended data saving subunit is used for saving the extended data after the file if the extended object corresponding to the extended data is the file.
[0142] Furthermore, the data storage module 220 includes: a second data storage submodule, wherein:
[0143] The second data saving submodule is used to save the graffiti data into the file in a binary format based on the pen type attribute and the track point attribute.
[0144] Furthermore, the data storage device 200 further includes: a display instruction response module and a graffiti data restoration module, wherein:
[0145] The display instruction response module is used to obtain the pen type attribute and the track point attribute from the file in response to the display instruction for the graffiti data.
[0146] The graffiti data restoration module is used to restore and display the graffiti data based on the pen type attribute and the track point attribute.
[0147] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0148] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0149] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.
[0150] See also Fig.11, which shows a structural block diagram of an electronic device 100 provided in an embodiment of the present application. The electronic device 100 may be an electronic device capable of running applications, such as a smart phone, a tablet computer, an e-book, etc. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications 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 execute the method described in the aforementioned method embodiment.
[0151] Among them, the processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 110 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented separately through a communication chip.
[0152] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). The memory 120 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the electronic device 100 during use.
[0153] See also Fig.12 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 300 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0154] The computer readable storage medium 300 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 300 includes a non-transitory computer-readable storage medium. The computer readable storage medium 300 has storage space for program code 310 that performs any method steps in the above method. These program codes can be read from or written to one or more computer program products. The program code 310 can be compressed, for example, in an appropriate form.
[0155] In summary, the data saving method, device, electronic device and storage medium provided in the embodiments of the present application obtain graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen and the thickness of the pen tip, and the track point attributes include the coordinates of the track points that constitute the graffiti data. Based on the pen type attributes and the track point attributes, the graffiti data is saved to a file, so that the graffiti data is saved by saving the pen type attributes and the track point attributes of the graffiti data, and the graffiti data can be saved efficiently and quickly to facilitate secondary editing by users, thereby improving the user experience.
[0156] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements 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 the present application.
Claims
1. A method for storing data, characterized in that: The method comprises: Acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen, and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data, and the graffiti data is composed of at least one stroke; Determining a pen type attribute corresponding to each of the at least one stroke and a track point attribute corresponding to each of the at least one stroke; Based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke, the at least one stroke is saved into a file, wherein the step of saving the at least one stroke into the file based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke comprises: acquiring the track point attribute corresponding to the stroke and creating a stroke head corresponding to the stroke, wherein the stroke head comprises the pen type attribute corresponding to the stroke, the end position of the track point attribute in the file and the track point length, and the stroke is saved into the file based on the stroke head corresponding to the stroke and the track point attribute corresponding to the stroke; Based on the track point length, determining the storage length of the coordinates of the track points constituting the stroke in the file; Based on the storage length, the coordinates of the trajectory points of the stroke are read from the file.
2. The method according to claim 1, characterized in that The graffiti data is composed of a plurality of strokes, and the step of saving the at least one stroke into the file includes: The multiple strokes are saved in the file in sequence according to the drawing time corresponding to each of the multiple strokes from front to back.
3. The method according to claim 1, characterized in that The step of saving the at least one stroke to the file based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke comprises: Creating a file header corresponding to the graffiti data; Based on the pen type attribute corresponding to each of the at least one stroke and the track point attribute corresponding to each of the at least one stroke, the file header and the at least one stroke are saved in the file.
4. The method according to claim 1, characterized in that: The method further comprises: Get extended data; The extended data is saved based on the extended object corresponding to the extended data.
5. The method according to claim 4, characterized in that For each stroke of the at least one stroke, the step of saving the extended data based on the extended object corresponding to the extended data includes: If the extended object corresponding to the extended data is a trajectory point attribute of the stroke, then the extended data is saved after the stroke in the file; or If the extended object corresponding to the extended data is a stroke attribute of the stroke, then the extended data is saved after the stroke in the file; or If the extended object corresponding to the extended data is the file, the extended data is saved after the file.
6. The method according to any one of claims 1 to 5, characterized in that: After the graffiti data is saved in a file based on the pen type attribute and the track point attribute, the method further includes: In response to a display instruction for the graffiti data, acquiring the pen type attribute and the track point attribute from the file; Based on the pen type attribute and the track point attribute, the graffiti data is restored and displayed.
7. The method according to any one of claims 1 to 5, characterized in that: The step of saving the graffiti data to a file based on the pen type attribute and the track point attribute includes: Based on the pen type attribute and the track point attribute, the graffiti data is saved in the file in a binary format.
8. A data storage device, characterized in that: The device comprises: A data acquisition module, used to acquire graffiti data in the drawing process, wherein the graffiti data includes pen type attributes and track point attributes, wherein the pen type attributes include at least one of the type of pen, the color of the pen and the thickness of the pen tip, and the track point attributes include the coordinates of the track points constituting the graffiti data, and the graffiti data is composed of at least one stroke; A data saving module, used for determining the pen type attribute corresponding to each of the at least one strokes, and the track point attribute corresponding to each of the at least one strokes; based on the pen type attribute corresponding to each of the at least one strokes and the track point attribute corresponding to each of the at least one strokes, saving the at least one stroke into the file, wherein the step of saving the at least one stroke into the file based on the pen type attribute corresponding to each of the at least one strokes and the track point attribute corresponding to each of the at least one strokes comprises: obtaining the track point attribute corresponding to the stroke and creating a stroke head corresponding to the stroke, wherein the stroke head comprises the pen type attribute corresponding to the stroke, the end position of the track point attribute in the file, and the track point length; based on the stroke head corresponding to the stroke and the track point attribute corresponding to the stroke, saving the stroke into the file; based on the track point length, determining the storage length of the coordinates of the track points constituting the stroke in the file; based on the storage length, reading the coordinates of the track points of the stroke from the file.
9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory is coupled to the processor, and the memory stores instructions. When the instructions are executed by the processor, the processor executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by a processor to execute the method according to any one of claims 1 to 7.
