File storage method, device and equipment containing transparent background image

By obtaining and processing transparency values ​​in OFD documents, the transparency background images in OFD documents are stored based on lossless compression format, solving the problems of storage space and transmission speed, and achieving efficient image storage and transmission.

CN118760655BActive Publication Date: 2024-12-10AEROSPACE FOXIT SOFTWARE (BEIJING) CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411225353.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-12-10
Estimated Expiration
2044-09-03

AI Technical Summary

Technical Problem

When including transparency background images in OFD documents, it leads to increased storage space and slower file transfer.

Method used

By obtaining the pixel transparency value of the target file and when specific conditions are met, the target image is stored based on the lossless compression format, the transparency information is removed, only the RGB value is retained, and the transparency value is stored separately, so as to reduce storage space requirements and improve transmission efficiency.

Benefits of technology

It effectively reduces the need for image storage space, improves file transfer speed, and accurately and quickly restores the target image when needed to ensure the accuracy of information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760655B_ABST
    Figure CN118760655B_ABST
Patent Text Reader

Abstract

The present invention provides a file storage method, device and equipment containing a transparency background image, which relates to the field of computers. The method comprises: obtaining the transparency value of each pixel in a target image of a target file; when the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold value, storing the target image in a target file based on a target format to obtain a target image in a target format; the first pixel is a pixel of a first transparency value in the target image; the second pixel is a pixel of a second transparency value in the target image; the target image in the target format contains RGB values ​​of each pixel; and the first transparency value and the second transparency value are stored. The method of the embodiment of the present application effectively reduces the space required for image storage in a file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device and equipment for storing files containing transparent background images. Background Art

[0002] Open Fixed-Layout Document (OFD) is an electronic document format independently developed by China. Its technology has been widely used in China, especially in the fields of finance, insurance, government affairs, etc. OFD files can support image resources in various formats. These images are embedded in the document to enhance the readability and display effect of the document.

[0003] In the related art, when an OFD document includes a transparent background image, the OFD document requires more storage space and the file transmission speed is slow. Summary of the invention

[0004] The present invention provides a file storage method, device and equipment containing a transparent background image, so as to solve the defects in the prior art that when an OFD document contains a transparent background image, the OFD document requires more storage space and the file transmission speed is slow.

[0005] The present invention provides a method, device and equipment for storing files containing transparent background images, comprising the following steps.

[0006] Get the transparency value of each pixel in the target image of the target file;

[0007] In the case where the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold, the target image is stored in the target file based on the target format to obtain a target image in the target format; the first pixel is a pixel with a first transparency value in the target image; the second pixel is a pixel with a second transparency value in the target image; and the target image in the target format includes RGB values ​​of each pixel;

[0008] The first transparency value and the second transparency value are stored.

[0009] According to a file storage method containing a transparent background image provided by the present invention, storing the target image based on a target format to obtain the target image in the target format includes:

[0010] When the transparency of a pixel in the target image is a first transparency value and the RGB value of the pixel is 0, updating the RGB value of the pixel to the first value;

[0011] When the transparency of a pixel in the target image is a second transparency value, updating the RGB value of the pixel to 0;

[0012] A target image in the target format is obtained according to the updated RGB value of the pixel and the target format.

[0013] According to a method for storing a file containing a transparent background image provided by the present invention, the target format includes:

[0014] Lossless compression image format.

[0015] According to a file storage method containing a transparent background image provided by the present invention, the transparency value of each pixel is determined according to the RGB value of each pixel in the target image of the target format and the first transparency value and the second transparency value stored;

[0016] The target image is restored according to the RGB value of each pixel in the target image of the target format and the transparency value of each pixel.

[0017] According to a file storage method containing a transparent background image provided by the present invention, the transparency value of each pixel is determined according to the RGB value of each pixel in the target image of the target format and the first transparency value and the second transparency value stored, including:

[0018] When the RGB value of the pixel is 0, the transparency of the pixel is a second transparency value;

[0019] When the RGB value of the pixel is non-zero, the transparency of the pixel is a first transparency value.

[0020] According to a file storage method containing a transparent background image provided by the present invention, after obtaining the transparency value of each pixel in the target image of the target file, the method further includes:

[0021] When the difference between the transparency value of the pixel and the first transparency value is less than a preset first threshold, updating the transparency value of the pixel to the first transparency value;

[0022] When the difference between the transparency value of the pixel and the first transparency value is smaller than a preset second threshold, the transparency value of the pixel is updated to the second transparency value.

[0023] The present invention also provides a file storage containing a transparency background image, comprising the following modules:

[0024] An acquisition module, used for acquiring the transparency value of each pixel in the target image of the target file;

[0025] A storage module, configured to store the target image based on a target format in the target file to obtain a target image in a target format when a quotient of a sum of a first number of pixels and a second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold; the first pixel is a pixel of a first transparency value in the target image; the second pixel is a pixel of a second transparency value in the target image; and the target image in the target format includes RGB values ​​of each pixel;

[0026] The first transparency value and the second transparency value are stored.

[0027] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the file storage method containing a transparent background image as described in any one of the above methods is implemented.

[0028] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the file storage method containing a transparent background image as described in any one of the above methods is implemented.

[0029] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method for storing a file containing a transparent background image as described in any one of the above is implemented.

[0030] The file storage method, device and equipment including a transparency background image provided by the present invention, when the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold value, that is, when the target image is not a gradient transparency, the target image is stored based on the target format to obtain a target image in the target format including the RGB value of each pixel, so that the target image in the target format no longer includes transparency information, but only includes the RGB information of the pixel, which can effectively reduce the space required for image storage. In addition, the first transparency value and the second transparency value are stored separately, so that when the target image needs to be restored and accurately displayed, the target image can be restored accurately and quickly based on the stored first transparency and second transparency, thereby ensuring the accuracy of the target image information. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0032] Figure 1 It is a flow chart of a method for storing a file including a transparent background image provided by the present invention.

[0033] Figure 2 It is a schematic diagram of a transparent background image provided by the present invention.

[0034] Figure 3 It is a schematic diagram of the effect of the file storage method containing a transparent background image provided by the present invention.

[0035] Figure 4 It is a structural schematic diagram of a file storage device including a transparency background image provided by the present invention.

[0036] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0038] In order to facilitate a clearer understanding of the technical solutions of the embodiments of the present application, some technical contents related to the embodiments of the present application are first introduced.

[0039] OFD (Open Fixed-Layout Document) is an electronic document format independently developed by China. Its technology has been widely used in China, especially in the fields of finance, insurance, government affairs, etc. OFD files can support image resources in various formats. These images are embedded in the document to enhance the readability and display effect of the document.

[0040] PNG (Portable Network Graphics) is a web-based image format developed by W3C in 1996. The file extension is .png. This format supports transparency effects and can define 256 transparency levels for images, so that the edges of color images can blend smoothly with any background, thus eliminating jagged edges. PNG is not limited to 256 colors, but also provides support for 24-bit and 48-bit true color images.

[0041] TIFF (Tagged Image File Format) is a file format used to store image data, including photographs and artistic images. The TIFF format is widely accepted and used for its flexibility, scalability, and cross-platform compatibility. It can handle multiple images and data in one file by including "tags" in the file header. Tags can indicate basic geometric dimensions of the image such as image size or define how the image data is arranged and whether various image compression options are used. For example, TIFF can contain images compressed with JPEG and run-length encoding. TIFF files can also contain vector-based cropped areas (cuts or outlines that make up the main image). The ability to store images in a lossless format makes TIFF files an effective method for image archiving. Unlike JPEG, TIFF files can be edited and restored without compression loss. Some other TIFF file options include multiple layers or multiple pages.

[0042] JPG stands for Joint Photographic Experts Group, which is a lossy compression format. This format was developed by the International Organization for Standardization (ISO) and is a compression standard for continuous-tone still images. The file extension of JPEG format is usually ".jpg" or ".jpeg".

[0043] A binary image is a special type of image, which is characterized by the fact that each pixel on the image has only two possible values ​​or grayscale states, usually represented as black and white.

[0044] Among them, lossless image formats such as TIF / PNG require more storage space than lossy compressed image formats such as JPG. The ImageMask parameter is used in the OFD standard to introduce binary images. The size of the OFD file is reduced by mixing binary images and JPG, and images with transparent backgrounds are supported.

[0045] Combine the following Figure 1-Figure 5 The present invention describes a method, device and apparatus for storing a file containing a transparent background image.

[0046] Figure 1 FIG. 1 is one of the flow charts of the method for storing a file containing a transparent background image provided by the present invention. Figure 1 As shown, the method includes the following:

[0047] Step 101: Obtain the transparency value of each pixel in the target image of the target file.

[0048] Specifically, in the prior art, when an OFD document includes a transparent background image, the OFD document requires more storage space and the file transmission speed is slow.

[0049] In order to solve the above problem, in the embodiment of the present application, the transparency value of each pixel in the target image of the target file is first obtained. For example, a document containing a transparent background image such as Figure 2 Optionally, the target file may be an OFD file, or other types of files, such as PDF, EXCEL, and other files containing transparent background images.

[0050] Step 102: When the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold, the target image is stored in a target file based on a target format to obtain a target image in a target format; the first pixel is a pixel of a first transparency value in the target image; the second pixel is a pixel of a second transparency value in the target image; and the target image in the target format includes RGB values ​​of each pixel.

[0051] Specifically, the background of the picture containing the transparent background may be to achieve the effect of gradient. If such pictures are directly subjected to lossy compression, the gradient background will be lost. Therefore, the present application first analyzes and judges the target image of the target file to determine whether it meets the optimization conditions, thereby avoiding the occurrence of the problem of losing its gradient background caused by direct lossy compression. Optionally, when the sum of the first number of pixels and the second number of pixels in the target image and the quotient of all the numbers of pixels in the target image are greater than the threshold, that is, when the target image is not a gradient transparency, the target image is stored based on the target format, and the target image of the obtained target format contains the RGB value of each pixel. That is, the target image in the target format no longer includes transparency information, but only includes the RGB information of the pixel, thereby effectively reducing the image storage space. Optionally, the threshold can be 100%, that is, the target image only includes pixels of two transparency levels. Optionally, the threshold can also be taken according to actual needs, such as taking a value of 99%, that is, the vast majority of pixels in the target image are pixels of the first transparency and pixels of the second transparency, that is, when the target image is not a gradient transparency, the target image can be optimized before storage. Optionally, the first transparency value is 255 and the second transparency value is 0.

[0052] Step 103: Store the first transparency value and the second transparency value.

[0053] Specifically, when the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold, that is, when the target image does not have a gradient transparency, the target image is stored based on the target format to obtain the target image in the target format containing the RGB values ​​of each pixel. In the embodiment of the present application, the first transparency value and the second transparency value are further stored. On the one hand, the target image in the target format no longer includes transparency information, but only includes the RGB information of the pixels, thereby effectively reducing the space required for image storage. On the other hand, the first transparency value and the second transparency value are stored separately in the text, so that when the target image needs to be restored and accurately displayed, the target image can be restored accurately and quickly based on the stored first transparency and second transparency, thereby ensuring the accuracy of the target image information.

[0054] In the method of the above embodiment, when the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold value, that is, when the target image is not a gradient transparency, the target image is stored based on the target format to obtain a target image in the target format containing the RGB values ​​of each pixel, so that the target image in the target format no longer includes transparency information, but only includes the RGB information of the pixel, which can effectively reduce the space required for image storage. In addition, the first transparency value and the second transparency value are stored separately, so that when the target image needs to be restored and accurately displayed, the target image can be restored accurately and quickly based on the stored first transparency and second transparency, thereby ensuring the accuracy of the target image information.

[0055] In one embodiment, storing the target image based on the target format to obtain the target image in the target format includes:

[0056] When the transparency of a pixel in the target image is a first transparency value and the RGB value of the pixel is 0, updating the RGB value of the pixel to the first value;

[0057] When the transparency of the pixel in the target image is the second transparency value, updating the RGB value of the pixel to 0;

[0058] A target image in a target format is obtained according to the updated RGB value of the pixel and the target format.

[0059] Specifically, in the embodiment of the present application, when the transparency of the pixel in the target image is the second transparency value, the RGB value of the pixel is updated to 0; when the transparency of the pixel in the target image is the first transparency value and the RGB value of the pixel is 0, the RGB value of the pixel is updated to the first value, thereby accurately establishing the relationship between the RGB value of the pixel and the pixel transparency, and then based on the relationship between the RGB value of the pixel and the pixel transparency, the pixel transparency can be quickly and accurately determined based on the RGB value of the pixel, thereby effectively reducing the storage space while accurately and quickly restoring the target image.

[0060] The method of the above embodiment accurately establishes the relationship between the RGB value of the pixel and the pixel transparency, and based on the relationship between the RGB value of the pixel and the pixel transparency, the pixel transparency can be quickly and accurately determined based on the RGB value of the pixel, thereby effectively reducing the storage space while accurately and quickly restoring the target image.

[0061] In one embodiment, the target format includes:

[0062] Lossless compression image format.

[0063] Specifically, the target image in the target format of the present application is a lossless compressed image format, that is, on the one hand, the storage space required for the image is effectively reduced through lossless compression, and on the other hand, because the target image in the target format no longer includes transparency information, but only includes RGB information of the pixel, the image storage space is reduced to the maximum extent through the above two dimensions, and the transmission efficiency of the target document is improved. Optionally, the lossless compressed image format can be in JPG format or other formats, which is not limited in the embodiments of the present application.

[0064] The method of the above embodiment, on the one hand, can reduce the storage space of the image through compression while ensuring the quality of the target image through lossless compression; on the other hand, since the target image in the target format no longer includes transparency information but only includes the RGB information of the pixel, the image storage space is minimized through the above two dimensions, thereby improving the transmission efficiency of the target document.

[0065] In one embodiment, the transparency value of each pixel is determined according to the RGB value of each pixel in the target image of the target format and the stored first transparency value and second transparency value;

[0066] The target image is restored according to the RGB value of each pixel and the transparency value of each pixel in the target image of the target format.

[0067] Specifically, in the embodiment of the present application, when the sum of the first number of pixels and the second number of pixels in the target image and the quotient of all the pixels in the target image are greater than a threshold value, that is, when the target image is not a gradient transparency, the target image is stored based on the target format to obtain a target image in the target format containing the RGB values ​​of each pixel, so that the target image in the target format no longer includes transparency information, but only includes the RGB information of the pixel, which can effectively reduce the space for image storage. In addition, the first transparency value and the second transparency value are stored separately, so that when the target image needs to be restored and accurately displayed, the target image can be restored accurately and quickly based on the stored first transparency and second transparency, thereby ensuring the accuracy of the target image information.

[0068] Optionally, in the process of restoring the target image, the embodiment of the present application determines the transparency value of each pixel according to the RGB value of each pixel in the target image of the target format and the stored first transparency value and second transparency value, thereby obtaining the RGB value and transparency value of each pixel in the target image, and obtaining all the information required for restoring the target image. Then, according to the RGB value and transparency value of each pixel in the target image of the target format, the target image can be accurately and quickly restored, thereby reducing the storage space of the target image while also accurately and quickly restoring the target image, and at the same time meeting the storage requirements of the target file and the accuracy and integrity of the target document.

[0069] The method of the above embodiment determines the transparency value of each pixel according to the RGB value of each pixel in the target image of the target format and the stored first transparency value and second transparency value, thereby obtaining all the information required for restoring the target image, and then the target image can be restored accurately and quickly, thereby reducing the storage space of the target image and also accurately and quickly restoring the target image.

[0070] In one embodiment, determining the transparency value of each pixel according to the RGB value of each pixel in the target image of the target format and the stored first transparency value and second transparency value includes:

[0071] When the RGB value of the pixel is 0, the transparency of the pixel is the second transparency value;

[0072] When the RGB value of the pixel is non-zero, the transparency of the pixel is a first transparency value.

[0073] Specifically, in the embodiment of the present application, when the RGB value of the pixel is 0, the transparency of the pixel is determined to be the second transparency value; when the RGB value of the pixel is non-0, the transparency of the pixel is determined to be the first transparency value, so that based on the relationship between the RGB value of the pixel and the transparency of the pixel, the pixel transparency can be quickly and accurately determined, thereby effectively reducing the storage space while accurately and quickly restoring the target image.

[0074] The method of the above embodiment can quickly and accurately determine the pixel transparency based on the relationship between the RGB value of the pixel and the transparency of the pixel, thereby effectively reducing the storage space and accurately and quickly restoring the target image.

[0075] In one embodiment, after obtaining the transparency value of each pixel in the target image of the target file, the method further includes:

[0076] When the difference between the transparency value of the pixel and the first transparency value is less than a preset first threshold, updating the transparency value of the pixel to the first transparency value;

[0077] When the difference between the transparency value of the pixel and the first transparency value is smaller than a preset second threshold, the transparency value of the pixel is updated to the second transparency value.

[0078] Specifically, the present application achieves accurate calculation of the first number of pixels and the second number of pixels in the target image by updating the transparency value of the pixel to the first transparency value when the difference between the transparency value of the pixel and the first transparency value is less than a preset first threshold; and updating the transparency value of the pixel to the second transparency value when the difference between the transparency value of the pixel and the first transparency value is less than a preset second threshold. Therefore, the present application can accurately analyze and judge the image containing the transparent background to determine whether it meets the optimization conditions, thereby effectively avoiding the problem of losing the gradient background due to direct lossy compression.

[0079] The method of the above embodiment achieves accurate calculation of the first number of pixels and the second number of pixels in the target image by updating the transparency value of the pixel to the first transparency value when the difference between the transparency value of the pixel and the first transparency value is less than the preset first threshold value; and updating the transparency value of the pixel to the second transparency value when the difference between the transparency value of the pixel and the first transparency value is less than the preset second threshold value, thereby accurately analyzing and judging the image containing the transparent background to determine whether it meets the optimization conditions, thereby effectively avoiding the problem of losing the gradient background caused by direct lossy compression.

[0080] Exemplarily, the specific process of the file storage method containing a transparent background image provided in the embodiment of the present application is as follows:

[0081] 1. Storage Optimization

[0082] 1.1. Determine whether the image resource file can be optimized.

[0083] For images with transparent backgrounds, the background may be used to achieve a gradient effect. Direct lossy compression of such images will result in the loss of the gradient background. Therefore, it is necessary to make a judgment on the image in advance:

[0084] a. Load the image into memory as a bitmap (RGBA);

[0085] b. Extract the foreground and background transparency values ​​(alpha) of the image, that is, determine the transparency of all pixels and classify them.

[0086] Among them, the foreground transparency value alpha is recorded as a1 (usually 255);

[0087] Background transparency value alpha, denoted as a2 (usually 0);

[0088] And it satisfies (where b is a preset threshold of the transparency difference between the foreground and the background):

[0089] a1>a2&&(a1-a2)>b.

[0090] c. According to the transparency value alpha (denoted as A) of the bitmap in the image and the preset error range value Δ, the pixels of the image are classified and counted G1 (foreground pixel count) / G2 (background pixel count):

[0091] If (abs(A-a1)<= Δ)

[0092] THEN

[0093] G1+1

[0094] ENDIF

[0095] IF (abs(A-a2)<= Δ)

[0096] THEN

[0097] G2+1

[0098] ENDIF

[0099] D. Calculate the ratio of foreground and background pixels to the entire image:

[0100] IF (G1+G2) / G>= β

[0101] THEN

[0102] Images can be optimized

[0103] ENDIF

[0104] (Where G is the total number of pixels in the image, β is the preset threshold, which can be adjusted according to the actual rendering effect requirements)

[0105] For example, if the transparency value of each pixel in the image is taken, if the transparency value of 1000 pixels is divided into two types, that is, it is not a gradient transparency, then it can be optimized. If the transparency value of 1000 pixels is divided into multiple types, that is, the image contains a gradient transparency background, then it cannot be optimized.

[0106] 1.2. Process the transparency value alpha of the pixels of the images that meet the optimization conditions

[0107] A. Processing of special pixels, replacing them with approximate values:

[0108] IF

[0109] Foreground pixel &&RGB = (0,0,0)

[0110] THEN

[0111] RGBA = (0,0,1, a1)

[0112] ENDIF

[0113] That is, if it is the foreground and it is black, then RGB is set to 001, which is very close to black, so it can effectively avoid the image being restored incorrectly and restored to transparent. That is, by updating the RGB value of the pixel to a point close to black, it will still be a black point when restored, and will not be restored to a transparent point.

[0114] B. Uniform adjustment of RGBA values ​​of background pixels

[0115] IF

[0116] Background pixels

[0117] THEN

[0118] RGBA = (0,0,0,a2)

[0119] ENDIF

[0120] C. Processing of foreground pixels

[0121] IF

[0122] Foreground pixels

[0123] THEN

[0124] RGBA = (R,G,B,a1)

[0125] ENDIF

[0126] 1.3. Save the adjusted memory image in the specified format (JPG)

[0127] That is, by losing transparency information, the size of the image can be effectively reduced, and the storage space can be reduced. The size of the image containing transparency information is much larger than the size of the image without transparency information. In this application, by optimizing the image, the image does not contain transparency information, and the two transparency values ​​are stored separately in the text, thereby effectively reducing the size of the image and accurately and quickly restoring the image.

[0128] 1.4. Locate the XML node "ofd:ImageObject" of the image resource object in the generated OFD file and set the custom attributes of the node:

[0129] BackGroundAlpha = a2&&ForeGroundAlpha = a1

[0130] Optionally, the transparency value may be stored separately in text, or in memory, or in any other location, which is not limited in the embodiments of the present application.

[0131] 2. Restore rendering:

[0132] Load the image into memory as a bitmap

[0133] Restore pixels:

[0134] IF

[0135] RGB = (0,0,0)

[0136] THEN

[0137] RGBA = (0,0,0,a2)

[0138] ELSE

[0139] RGBA = (R,G,B,a1)

[0140] ENDIF

[0141] (where a2 is the alpha value of the background, and a1 is the alpha value of the foreground).

[0142] For example, Figure 3 As shown, the sizes of the OFD files stored in the above manner using three different schemes are shown. It can be seen that the size of the OFD file using the present invention is significantly smaller than the other two schemes, wherein:

[0143] 1. The test file 0.ofd is the original OFD using the 'PNG' image resource.

[0144] 2. Test file 1.ofd is an OFD that uses the 'binary image and JPG' image resources.

[0145] 3. Test file 2.ofd is an OFD that uses 'custom parameters and JPG' image resources.

[0146] The method of the above embodiment, under the premise of retaining the transparency of the picture in OFD, can save file storage space and significantly improve the file transmission efficiency by using lossy compressed pictures to replace lossless compressed pictures, and can achieve the effect of supporting transparent background without using binary pictures; and can determine the compression effect of resource pictures according to specific needs, thereby achieving the effect of reducing the storage size of OFD files by optimizing the picture resources in OFD.

[0147] The following is a description of a file storage device containing a transparency background image provided by the present invention. The file storage device containing a transparency background image described below and the file storage method containing a transparency background image described above can be referred to in correspondence with each other. Figure 4 As shown, including:

[0148] An acquisition module 410 is used to acquire the transparency value of each pixel in the target image of the target file;

[0149] The storage module 420 is used to store the target image in the target file based on the target format to obtain the target image in the target format when the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold value; the first pixel is a pixel with a first transparency value in the target image; the second pixel is a pixel with a second transparency value in the target image; and the target image in the target format includes RGB values ​​of each pixel;

[0150] The first transparency value and the second transparency value are stored.

[0151] Optionally, the storage module 420 is specifically configured to update the RGB value of the pixel to the first value when the transparency of the pixel in the target image is the first transparency value and the RGB value of the pixel is 0;

[0152] When the transparency of the pixel in the target image is the second transparency value, updating the RGB value of the pixel to 0;

[0153] A target image in a target format is obtained according to the updated RGB value of the pixel and the target format.

[0154] Optionally, the target format includes:

[0155] Lossless compression image format.

[0156] Optionally, the storage module 420 is specifically used to determine the transparency value of each pixel according to the RGB value of each pixel in the target image of the target format and the stored first transparency value and second transparency value;

[0157] The target image is restored according to the RGB value of each pixel and the transparency value of each pixel in the target image of the target format.

[0158] Optionally, the storage module 420 is specifically configured to, when the RGB value of the pixel is 0, the transparency of the pixel is a second transparency value;

[0159] When the RGB value of the pixel is non-zero, the transparency of the pixel is a first transparency value.

[0160] Optionally, the acquisition module 410 is specifically configured to update the transparency value of the pixel to the first transparency value when the difference between the transparency value of the pixel and the first transparency value is less than a preset first threshold;

[0161] When the difference between the transparency value of the pixel and the first transparency value is smaller than a preset second threshold, the transparency value of the pixel is updated to the second transparency value.

[0162] Figure 5 An example of a physical structure diagram of an electronic device is provided, and the electronic device may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute a file storage method containing a transparent background image, and the method includes: obtaining the transparency value of each pixel in the target image of the target file; when the sum of the first number of pixels and the second number of pixels in the target image and the quotient of all the numbers of pixels in the target image are greater than a threshold, storing the target image in the target file based on the target format to obtain the target image in the target format; the first pixel is a pixel of the first transparency value in the target image; the second pixel is a pixel of the second transparency value in the target image; the target image in the target format contains the RGB value of each pixel; and the first transparency value and the second transparency value are stored.

[0163] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0164] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the file storage method containing a transparent background image provided by the above methods, and the method includes: obtaining the transparency value of each pixel in the target image of the target file; when the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold, storing the target image based on a target format in the target file to obtain a target image in the target format; the first pixel is a pixel with a first transparency value in the target image; the second pixel is a pixel with a second transparency value in the target image; the target image in the target format contains RGB values ​​of each pixel; and storing the first transparency value and the second transparency value.

[0165] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute a file storage method containing a transparent background image provided by the above-mentioned methods, the method comprising: obtaining the transparency value of each pixel in the target image of the target file; when the quotient of the sum of the first number of pixels and the second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold, storing the target image based on a target format in the target file to obtain a target image in a target format; the first pixel is a pixel of a first transparency value in the target image; the second pixel is a pixel of a second transparency value in the target image; the target image in the target format contains RGB values ​​of each pixel; and storing the first transparency value and the second transparency value.

[0166] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0167] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0168] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention 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 deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for storing files containing transparent background images, characterized in that: include: Get the transparency value of each pixel in the target image of the target file; When a quotient of a sum of a first number of pixels and a second number of pixels in the target image and a number of all pixels in the target image is greater than a threshold, storing the target image in the target file based on a target format to obtain a target image in a target format; The first pixel is a pixel of a first transparency value in the target image; the second pixel is a pixel of a second transparency value in the target image; the target image in the target format only includes the RGB value of each pixel and does not include transparency information; storing the first transparency value and the second transparency value; The step of storing the target image based on a target format to obtain the target image in the target format includes: When the transparency of a pixel in the target image is a first transparency value and the RGB value of the pixel is 0, updating the RGB value of the pixel to the first value; When the transparency of a pixel in the target image is a second transparency value, updating the RGB value of the pixel to 0; A target image in the target format is obtained according to the updated RGB value of the pixel and the target format.

2. The method for storing a file containing a transparent background image according to claim 1, characterized in that: The target formats include: Lossless compression image format.

3. The method for storing a file containing a transparent background image according to claim 1 or 2, characterized in that: Also includes: Determine the transparency value of each pixel according to the RGB value of each pixel in the target image of the target format and the first transparency value and the second transparency value stored; The target image is restored according to the RGB value of each pixel in the target image of the target format and the transparency value of each pixel.

4. The method for storing a file containing a transparent background image according to claim 3, characterized in that: Determining the transparency value of each pixel according to the RGB value of each pixel in the target image of the target format and the first transparency value and the second transparency value stored includes: When the RGB value of the pixel is 0, the transparency of the pixel is a second transparency value; When the RGB value of the pixel is non-zero, the transparency of the pixel is a first transparency value.

5. The method for storing a file containing a transparent background image according to claim 1 or 2, characterized in that: After obtaining the transparency value of each pixel in the target image of the target file, the method further includes: When the difference between the transparency value of the pixel and the first transparency value is less than a preset first threshold, updating the transparency value of the pixel to the first transparency value; When the difference between the transparency value of the pixel and the first transparency value is smaller than a preset second threshold, the transparency value of the pixel is updated to the second transparency value.

6. A file storage device containing a transparent background image, characterized in that: include: An acquisition module, used for acquiring the transparency value of each pixel in the target image of the target file; A storage module, configured to store the target image based on a target format in the target file to obtain a target image in a target format when a quotient of a sum of a first number of pixels and a second number of pixels in the target image and the number of all pixels in the target image is greater than a threshold; The first pixel is a pixel of a first transparency value in the target image; the second pixel is a pixel of a second transparency value in the target image; the target image in the target format only includes the RGB value of each pixel and does not include transparency information; storing the first transparency value and the second transparency value; The step of storing the target image based on a target format to obtain the target image in the target format includes: When the transparency of a pixel in the target image is a first transparency value and the RGB value of the pixel is 0, updating the RGB value of the pixel to the first value; When the transparency of a pixel in the target image is a second transparency value, updating the RGB value of the pixel to 0; A target image in the target format is obtained according to the updated RGB value of the pixel and the target format.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the file storage method containing a transparent background image as described in any one of claims 1 to 5 is implemented.

8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for storing a file containing a transparent background image as claimed in any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Compression method and device and decompression method and device for image with transparency

    CN103533352A

  • Picture file processing method and intelligent terminal

    CN107071514A

  • A picture file processing method

    CN109005426A

  • Image processing method and device, intelligent terminal and computer readable storage medium

    CN113645469A

  • Image compression method, restoration method, computing device and readable storage medium

    CN115550661A