Image storage method, image display method and related device

By extracting transparent and non-transparent pixel points in PNG format images and processing images stored in two JPG formats, the problem of reducing the size while maintaining transparency is solved, and efficient storage and display of images is achieved.

CN114443872BActive Publication Date: 2025-03-25CHINA TELECOM CLOUD TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111583258.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-22
Publication Date
2025-03-25
Estimated Expiration
2041-12-22

AI Technical Summary

Technical Problem

The prior art is difficult to reduce the volume of image files while keeping the image transparent. Images in JPG format do not support transparency, while images in PNG format are larger.

Method used

By extracting transparent and non-transparent pixel points in PNG format images, they are processed and stored as two JPG format images, one replaces transparent pixel points with a fixed grayscale value, and the other replaces non-transparent pixel points with a fixed grayscale value.

Benefits of technology

It realizes the characteristics of both transparency and small size, improving the image refresh speed and user viewing experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443872B_ABST
    Figure CN114443872B_ABST
Patent Text Reader

Abstract

The present application provides an image storage method, an image display method and related devices. Through the image storage method, a first image in PNG format can be stored as two second images in JPG format, ensuring that the image has the small volume characteristic of the JPG format; and through the image display method, the two second images stored by the image storage method can be used to restore the display effect of the first image, ensuring that the image has the transparent characteristic of the PNG format. Therefore, the present application can make the image have the advantages of transparency and small volume at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an image storage method, an image display method and related devices. Background Art

[0002] Image format refers to the format in which image files are stored, usually JPG format, PNG format, etc. Among them, JPG format uses lossy compression to reduce the size of the image, so users will see that as the file size is reduced, the image quality is also reduced, and the transparent area in the image is converted to a solid color; PNG format uses lossless compression to reduce the size of the image, while retaining the transparent area in the image, resulting in a slightly larger file. It can be seen that the image compression rate of JPG format is relatively high, but the image does not support transparency; although the image in PNG format supports transparency, the size is too large. Summary of the invention

[0003] In view of this, the embodiments of the present application provide an image storage method, an image display method and related devices, so as to make the image have the advantages of transparency and small size.

[0004] Therefore, an image storage method provided in an embodiment of the present application includes:

[0005] Provide a first image in PNG format;

[0006] Extracting transparent pixels and non-transparent pixels in the first image;

[0007] Processing the transparent pixel and the non-transparent pixel into two parts;

[0008] The transparent pixels of one of the portions are replaced with pixels having a first fixed gray value, and the non-transparent pixels are replaced with pixels having a second fixed gray value; and the transparent pixels of the other portion are replaced with pixels having the first fixed gray value, and the non-transparent pixels remain unchanged;

[0009] The pixels of the first fixed grayscale value and the pixels of the second fixed grayscale value are stored as a first second image in JPG format, and the pixels of the first fixed grayscale value and the non-transparent pixels are stored as a second second image in a second JPG format.

[0010] In some embodiments, in the above-mentioned image storage method provided in the embodiments of the present application, replacing the transparent pixel points with pixel points having a first fixed grayscale value specifically includes: replacing the transparent pixel points with black pixel points.

[0011] In some embodiments, in the above-mentioned image storage method provided in the embodiments of the present application, the non-transparent pixels are replaced with pixels having a second fixed grayscale value, specifically including: replacing the non-transparent pixels with white pixels.

[0012] On the other hand, the present application provides an image display method, comprising:

[0013] Acquire a first second image in JPG format and a second second image in JPG format stored by the above-mentioned image storage method;

[0014] Reading the pixel point at each corresponding position in the two second images;

[0015] Determine whether the pixels at the corresponding positions are all pixels with a first fixed grayscale value. If so, display the pixels with the first fixed grayscale value as transparent; if not, display the color channel values ​​of the non-transparent pixels in the second image in combination with the alpha channel with a value of 1.

[0016] In some embodiments, in the above-mentioned image display method provided in the embodiments of the present application, determining whether the pixel points at corresponding positions are all pixel points with a first fixed grayscale value specifically includes: determining whether the pixel points at corresponding positions are all black pixel points.

[0017] In some embodiments, in the above-mentioned image display method provided in the embodiments of the present application, determining whether the pixels at corresponding positions are all pixels having a first fixed grayscale value specifically includes:

[0018] Determine whether the pixels at the corresponding positions are all black pixels, or are white pixels and non-transparent pixels respectively.

[0019] In some embodiments, in the above-mentioned image display method provided in the embodiment of the present application, reading the pixel point at each corresponding position in the two second images specifically includes:

[0020] A new byte array is created, and the byte array is used to traverse the pixel points at each corresponding position in the two second images.

[0021] Based on the same inventive concept, an embodiment of the present application provides a computer program product, including a software code portion. When the computer program product runs on a computer, the software code portion is used to execute the above-mentioned image storage method and / or the above-mentioned image display method.

[0022] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above-mentioned image storage method and / or the above-mentioned image display method.

[0023] Based on the same inventive concept, an embodiment of the present application provides a computing device, including:

[0024] A memory for storing program instructions;

[0025] The processor is used to call the program instructions stored in the memory and execute the above-mentioned image storage method and / or the above-mentioned image display method according to the obtained program instructions.

[0026] The beneficial effects of this application are as follows:

[0027] In the image storage method, image display method and related devices provided in the embodiments of the present application, a first image in PNG format can be stored as two second images in JPG format through the image storage method, ensuring that the image has the small volume characteristic of the JPG format; and through the image display method, the two second images stored by the image storage method can be used to restore the display effect of the first image, ensuring that the image has the transparent characteristic of the PNG format. Therefore, the present application can enable the image to have the technical effects of transparency and small volume at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 A flowchart of an image storage method provided in an embodiment of the present application;

[0029] Figure 2 A first image in PNG format provided in an embodiment of the present application;

[0030] Figure 3 The second image in the first JPG format provided in the embodiment of the present application;

[0031] Figure 4 A second image in a second JPG format provided in an embodiment of the present application;

[0032] Figure 5 A flowchart of an image display method provided in an embodiment of the present application;

[0033] Figure 6 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0034] To make the purpose, technical scheme and advantages of the embodiment of the present application clearer, the technical scheme of the embodiment of the present application will be clearly and completely described below in conjunction with the drawings of the embodiment of the present application. Unless otherwise defined, the technical terms or scientific terms used herein should be the usual meanings understood by people with ordinary skills in the field to which the present application belongs. The "first", "second" and similar words used in the specification and claims of this application do not represent any order, quantity or importance, but are only used to distinguish similar objects. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described here can be implemented in an order other than the content illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0035] When browsing an album (such as a Sprite album) through a browser, the image refresh is slow due to the high image quality and large size of the PNG format; the image size of the JPG format is small, but it does not support transparency and the image quality is low, so images in both formats cannot meet the user's viewing experience.

[0036] In order to solve the above technical problems in the related art, the present application embodiment provides an image storage method, such as Figure 1 As shown, including:

[0037] S101, providing a first image in PNG format, such as Figure 2 As shown;

[0038] S102, extracting transparent pixels and non-transparent pixels in the first image; wherein transparent pixels do not have any color, and non-transparent pixels have colors, such as red pixels, green pixels, blue pixels, and pixels of other colors known to those skilled in the art;

[0039] S103, processing the transparent pixel and the non-transparent pixel into two copies, for example, two copies of the transparent pixel and the non-transparent pixel may be obtained by cloning;

[0040] S104, replacing transparent pixels of one of the copies with pixels having a first fixed gray value, and replacing non-transparent pixels with pixels having a second fixed gray value; and replacing transparent pixels of the other copy with pixels having the first fixed gray value, while keeping non-transparent pixels unchanged;

[0041] S105: storing the pixel points of the first fixed grayscale value and the pixel points of the second fixed grayscale value as a second image in a first JPG format (eg, Figure 3 ), and storing the pixels of the first fixed gray value and the non-transparent pixels as a second image in a second JPG format (as shown in Figure 4 shown).

[0042] In the above-mentioned image storage method provided in the embodiment of the present application, by storing a first image in PNG format as two second images in JPG format, it is ensured that the image has the small volume characteristic of the PNG format. Therefore, when applied to refreshing the atlas, the refresh speed can be increased, which is beneficial to improving the user's viewing experience.

[0043] In some embodiments, in the above-mentioned image storage method provided in the embodiment of the present application, in step S104, the transparent pixels are replaced with pixels having a first fixed gray value, and specifically, the transparent pixels can be replaced with black pixels, so as to facilitate storage and facilitate effective recognition in the subsequent image display process. Of course, the transparent pixels can also be replaced with pixels of other gray values, which is not limited here.

[0044] In some embodiments, in the above-mentioned image storage method provided in the embodiment of the present application, in step S104, the non-transparent pixels are replaced with pixels having a second fixed gray value, and specifically, the non-transparent pixels can be replaced with white pixels, so as to facilitate storage and facilitate effective identification in the subsequent image display process. Of course, the non-transparent pixels can also be replaced with pixels of other gray values, which is not limited here.

[0045] It can be understood that a specific embodiment provided by the present application can be that after the transparent pixels are replaced with black pixels and the non-transparent pixels are replaced with white pixels, the storage is Figure 2 The first second image in JPG format is a black and white image. The transparent pixels are replaced with black pixels, and the non-transparent pixels are kept unchanged, and the image is stored as Figure 3 A second image in JPG format is shown.

[0046] On the other hand, the present application also provides an image display method, such as Figure 5 As shown, including:

[0047] S501, acquiring a first second image in JPG format and a second second image in JPG format stored by the above-mentioned image storage method;

[0048] S502, reading the pixel point at each corresponding position in the two second images;

[0049] S503, determine whether the pixels at the corresponding positions are all pixels with a first fixed grayscale value, if so, display the pixels with the first fixed grayscale value as transparent, if not, combine the color channel values ​​(such as red channel value, green channel value and blue channel value) of the non-transparent pixels in the second second image with the alpha channel value of 1 for display. Generally, the alpha channel has a value range of 0 to 1, and the smaller the value, the higher the transparency, where 0 represents transparent and 1 represents opaque. By adding an alpha channel with a value of 1, the display effect of the PNG format can be restored more realistically.

[0050] In the above-mentioned image display method provided in the embodiment of the present application, the two second images in JPG format stored by the above-mentioned image storage method can be used to restore the display effect of the first image in PNG format, thereby ensuring that the image has the transparent characteristics of the PNG format. Therefore, when used to refresh the atlas, the display effect can be improved, which is beneficial to improving the user's viewing experience.

[0051] In some embodiments, the transparent pixels of the first image in PNG format correspond to the black pixels of the second image in the first JPG format, and the non-transparent pixels of the first image in PNG format correspond to the white pixels of the second image in the first JPG format; the transparent pixels of the first image in PNG format correspond to the black pixels of the second image in the second JPG format, and the non-transparent pixels of the first image in PNG format correspond to the remaining pixels of the second image in the second JPG format; therefore, in the above-mentioned image storage method provided in the embodiment of the present application, the above-mentioned step S503 determines whether the pixel points at the corresponding position are all pixel points with the first fixed grayscale value. Specifically, it can be determined whether the pixel points at the corresponding position are all black pixel points. When it is identified that the pixel points at the corresponding position are all black pixel points, it can be determined that the black pixel point corresponds to the transparent pixel point in the first image in PNG format, and therefore the black pixel point can be displayed transparently.

[0052] More specifically, in the above step S503, it is determined whether the pixels at the corresponding positions are all pixels with the first fixed grayscale value. Specifically, it can be determined whether the pixels at the corresponding positions are all black pixels, or white pixels and non-transparent pixels respectively. When it is identified that the pixels at the corresponding positions are all black pixels, it can be determined that the pixels at the current corresponding positions correspond to transparent pixels in the first image in PNG format, so the black pixels can be displayed transparently; when it is identified that the pixels at the corresponding positions are white pixels and non-transparent pixels respectively, it can be determined that the pixels at the current corresponding positions correspond to non-transparent pixels in the first image in PNG format, so the color channel values ​​of the non-transparent pixels in the second image can be combined with the alpha channel for display. In the above manner, the display effect of the PNG format can be restored better.

[0053] In some embodiments, in the above-mentioned image storage method provided in the embodiment of the present application, the above-mentioned step S502, reading the pixel points at each corresponding position in the two second images, can be specifically implemented in the following manner:

[0054] A new byte array is created, and the byte array is used to traverse the pixels at each corresponding position in the two second images (i.e., the first second image in JPG format and the second second image in JPG format). Since the byte array is a form of orderly organizing several variables of the same type for the convenience of processing in program design, the byte array is used to traverse the pixels at each corresponding position in the two second images, which greatly saves processing time and helps improve user experience.

[0055] Based on the same inventive concept, the embodiment of the present application provides a computer program product, including a software code portion. When the computer program product is run on a computer, the software code portion is used to execute the above-mentioned image storage method and / or image display method. Since the principle of solving the problem by the computer program product is similar to the principle of solving the problem by the above-mentioned image storage method and / or image display method, the implementation of the computer program product provided by the embodiment of the present application can refer to the implementation of the above-mentioned image storage method and / or image display method provided by the embodiment of the present application, and the repeated parts will not be repeated.

[0056] Optionally, the computer program product provided by the embodiment of the present application can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable signal medium can be and is not limited to a system, device or device of electricity, magnetism, light, electromagnetic, infrared or semiconductor, or any combination of the above. The readable storage medium can include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device or any suitable combination of the above. The software code part can be specified using any known or future developed programming language, such as a high-level programming language, such as objective-C, C, C++, C#, Java, Python, Javascript, other scripting languages, etc., or a low-level programming language, such as a machine language or an assembler.

[0057] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the above-mentioned image storage method and / or image display method. Since the principle of solving the problem by the computer-readable storage medium is similar to the principle of solving the problem by the above-mentioned image storage method and / or image display method, the implementation of the computer-readable storage medium provided by the embodiment of the present application can refer to the implementation of the above-mentioned image storage method and / or image display method provided by the embodiment of the present application, and the repeated parts will not be repeated.

[0058] Optionally, the above-mentioned computer-readable storage medium provided in the embodiments of the present application may be a non-temporary computer-readable medium, such as any available medium or data storage device that can be accessed by a computer, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor storage (such as ROMs, EPROMs, EEPROMs, non-volatile memories (NAND FLASH), solid-state drives (SSDs)), etc.

[0059] Based on the same inventive concept, the present application embodiment provides a computing device, such as Figure 6 As shown, it includes: a memory 601 for storing program instructions; a processor 602 for calling the program instructions stored in the memory 601, and executing the above-mentioned image storage method and / or image display method according to the obtained program instructions. Since the principle of solving the problem by the computing device is similar to the principle of solving the problem by the above-mentioned image storage method and / or image display method, the implementation of the computing device provided in the embodiment of the present application can refer to the implementation of the above-mentioned image storage method and / or image display method provided in the embodiment of the present application, and the repeated parts will not be repeated.

[0060] In some embodiments, in the above-mentioned computing device provided in the embodiment of the present application, the computing device may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a personal digital assistant (PDA), etc. The computing device may also include input / output devices, etc., wherein the input device may include a keyboard, a mouse, a touch screen, etc., and the output device may include a display device, such as a liquid crystal display (LCD), a cathode ray tube display (CRT), an organic electroluminescent display (OLED), a light emitting diode display (LED), a micro light emitting diode display (mini / micro LED), etc. The memory 601 may include a read-only memory (ROM) and a random access memory (RAM), and provide the processor 602 with program instructions and data stored in the memory 601. The memory 601 of the present application may be used to store the program of any image storage method and / or image display method provided in the embodiment of the present application. The processor 602 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or a complex programmable logic device (CPLD).

[0061] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0062] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0063] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.

[0064] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0065] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. An image storage method, characterized in that: include: Provide a first image in PNG format; Extracting transparent pixels and non-transparent pixels in the first image; Processing the transparent pixel and the non-transparent pixel into two parts; Replacing the transparent pixels of one of the copies with pixels having a first fixed grayscale value, and replacing the non-transparent pixels with pixels having a second fixed grayscale value; and replacing the transparent pixels of the other copy with pixels having the first fixed grayscale value, while the non-transparent pixels remain unchanged; Replacing the transparent pixels with pixels having the first fixed grayscale value specifically includes: replacing the transparent pixels with black pixels; Replacing the non-transparent pixels with pixels having the second fixed grayscale value specifically includes: replacing the non-transparent pixels with white pixels; The pixels of the first fixed grayscale value and the pixels of the second fixed grayscale value are stored as a first second image in JPG format, and the pixels of the first fixed grayscale value and the non-transparent pixels are stored as a second second image in a second JPG format.

2. An image display method, characterized in that: include: Acquire a first second image in JPG format and a second second image in JPG format stored by the image storage method according to claim 1; Reading the pixel point at each corresponding position in the two second images; Determine whether the pixels at the corresponding positions are all pixels with a first fixed grayscale value. If so, display the pixels with the first fixed grayscale value as transparent; if not, display the color channel values ​​of the non-transparent pixels in the second image in combination with the alpha channel with a value of 1.

3. The image display method according to claim 2, wherein: Determining whether all the pixels at the corresponding positions are pixels having a first fixed grayscale value specifically includes: determining whether all the pixels at the corresponding positions are black pixels.

4. The image display method according to claim 2, wherein: Determining whether the pixels at the corresponding positions are all pixels having a first fixed grayscale value specifically includes: Determine whether the pixels at the corresponding positions are all black pixels, or are white pixels and non-transparent pixels respectively.

5. The image display method according to claim 2, wherein: Reading the pixel point at each corresponding position in the two second images specifically includes: A new byte array is created, and the byte array is used to traverse the pixel points at each corresponding position in the two second images.

6. A computer program product, characterized in that It comprises a software code part, and when the computer program product is run on a computer, the software code part is used to execute the image storage method as claimed in claim 1 and / or the image display method as claimed in claim 2.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the image storage method according to claim 1 and / or the image display method according to claim 2.

8. A computing device, characterized in that include: A memory for storing program instructions; A processor, configured to call program instructions stored in the memory, and execute the image storage method as claimed in claim 1 and / or the image display method as claimed in claim 2 according to the obtained program instructions.

Citation Information

Patent Citations

  • Animation playing method, device, storage medium and terminal

    CN109272565A