Picture loading method and device
By classifying the resource size of the image and taking corresponding processing, such as automatic cropping and compression, combined with the cache mechanism of the client and server, the problem of taking into account quality, compression ratio and speed in image loading is solved, and the loading performance and user experience are improved .
Patent Information
- Application Number
- CN202411333788.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-07
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art is difficult to take into account image quality, compression ratio and reading speed in image loading. Especially in high-resolution rendering or professional use, the image quality loss is obvious, and the browser caching method does not have high utilization rate of storage resources.
Classify the image resource size, and adopt automatic cropping, lossy compression or lossless compression processing, and optimize image loading through the cache mechanism of the client and server, using a combination of in-memory database, browser cache and disk cache Image loading.
While maintaining high accuracy of pictures, the processing process of large resource images is simplified, the smoothness and user experience of picture loading are improved, the cost of optimization is balanced, and the resource utilization and storage management efficiency are improved.
Smart Images

Figure CN119271913A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of picture loading, and in particular to a picture loading method and device. Background Art
[0002] With the promotion of large screens for data visualization and analysis, and the gradual improvement of hardware device resolution, the requirements for the accuracy and quality of image materials have also increased. This has led to an increase in the size of image materials and an increase in the time it takes to load images. At present, the performance of image loading is generally optimized by compressing images, using browsers to cache images, and other means.
[0003] There are usually two ways to compress images, lossy compression and lossless compression. Lossy compression causes some data in the image to be intentionally deleted, and the deleted data cannot be restored. Lossy compression methods take advantage of the limitations of human visual perception, such as insensitivity to certain frequencies and tolerance to time, to reduce the size of the data, thereby achieving a higher compression ratio, but lossy compression methods will affect the final presentation quality of the image data, especially when rendering at high resolution or applying the image to professional purposes, the loss of image quality will be more obvious. Lossless compression ensures the integrity of the original data and can be fully restored after decompression. The disadvantage is that the compression ratio obtained is limited.
[0004] The purpose of browser caching images is to save network resources and speed up image browsing. The browser stores the most recently requested images on the user's disk. When the visitor requests to access the image again, the browser can read the image from the user's disk, which can speed up the viewing of the image.
[0005] The above-mentioned image loading methods are difficult to take into account the problems of image quality, compression ratio and reading speed. At present, a method for loading images that can take into account the above-mentioned requirements is yet to be proposed to improve the overall performance of image loading. Summary of the invention
[0006] Based on the above problems, the present application provides a method and device for loading an image, the purpose of which is to improve the performance of loading an image.
[0007] The embodiments of the present application disclose the following technical solutions:
[0008] The first aspect of the present application provides a method for loading an image, the method comprising:
[0009] Receive the picture uploaded by the client and determine the resource size of the picture;
[0010] Classifying the picture according to the resource amount interval to which the resource size of the picture belongs, and the correspondence between multiple resource amount intervals and picture categories;
[0011] If the category of the picture is the first category, the picture is automatically cut into a plurality of sub-pictures; wherein the first category is the picture category corresponding to the largest resource amount interval;
[0012] The multiple sub-pictures are provided to the client so that the client caches the multiple sub-pictures and performs a picture loading operation; wherein the manner in which the client caches the multiple sub-pictures is determined based on the resource size of the sub-pictures; and the manner in which the client performs the picture loading operation is determined based on the resource size of the loaded picture.
[0013] The resource amount interval corresponding to the first category is [10MB, +∞); the method further includes:
[0014] If the category of the picture is the second category, the picture is automatically lossily compressed to generate a thumbnail; the resource amount interval corresponding to the second category is [1MB, 10MB);
[0015] If the category of the picture is the third category and the resource size of the picture is in the range of (0, 500KB), the picture is not compressed;
[0016] If the category of the image is the third category and the resource size of the image is in the interval [500KB, 1MB), the image is losslessly compressed; the resource size interval corresponding to the third category is (0, 1MB).
[0017] The client caches the multiple sub-images in the following manner:
[0018] Determine whether the resource size of the sub-image is in the range of [1MB, 10MB). If so, cache the sub-image using the client's memory database cache.
[0019] If not, the sub-image is cached using the client's browser cache and disk cache.
[0020] In an optional implementation, the client caches the picture further comprising:
[0021] If the category of the picture is the second category, providing the picture to the client, so that the client caches the picture and performs a picture loading operation;
[0022] The original image of the image is cached by a client's memory database cache, and the thumbnail of the image is cached by a browser cache and a disk cache;
[0023] If the category of the picture is the third category, the picture is provided to the client, so that the client determines whether to cache according to the resource size of the picture, and performs a picture loading operation; wherein, if the resource size of the picture is in the interval of (0, 500KB), the client caches the picture by browser cache and disk cache; if the resource size of the picture is in the interval of [500KB, 1MB), the picture is losslessly compressed, and the client caches the losslessly compressed picture by browser cache and disk cache.
[0024] The client performs the image loading operation in the following manner:
[0025] Read multiple block resources of the client's memory database in parallel to determine whether the memory database hits the multiple sub-images;
[0026] If so, the multiple sub-images are loaded from the multiple block resources.
[0027] In an optional implementation, the client performs the image loading operation in a manner further comprising:
[0028] If the category of the picture is the second category, the client reads the original picture and thumbnail of the picture in parallel from the client's memory database, browser memory and disk memory, and determines whether the cache medium hits or not. If it hits, the thumbnail is loaded first and then the original picture is loaded;
[0029] If the category of the image is the third category, the client reads the image in the browser memory and disk memory of the client, determines whether the cache medium hits or not, and if so, directly loads the image.
[0030] In an optional implementation, the image loading method further includes:
[0031] The server stores the pictures uploaded by the client and the processing results of the pictures;
[0032] The server responds to the client's picture resource reading request and provides the client with a picture corresponding to the picture resource reading request; the picture resource reading request is generated by the client and sent to the server under the condition that the client does not hit the picture resource in the cache medium.
[0033] A second aspect of the present application provides another method for loading an image, the method comprising:
[0034] Uploading the image to the server, so that the server classifies the image according to the resource size interval to which the resource size of the image belongs and the correspondence between the multiple resource size intervals and the image categories;
[0035] Receive the classification result of the image by the server, and if the image is of the first category, cache multiple sub-images generated after the image is automatically cropped by the server; wherein the manner of caching the multiple sub-images is determined based on the resource size of the sub-images; the first category is the image category corresponding to the largest resource amount interval;
[0036] An image loading operation is performed based on multiple cached sub-images; wherein the image loading operation is performed in a manner determined based on a resource size of the loaded image.
[0037] The method of caching the sub-image generated after the image is automatically cropped by the server is:
[0038] Determine whether the resource size of the sub-image is in the range of [1MB, 10MB). If so, cache the sub-image using the memory database cache method;
[0039] If not, use browser cache and disk cache to cache the sub-images.
[0040] The resource amount interval corresponding to the first category is [10MB, +∞); the method further includes:
[0041] If the image is of the second category, the original image of the image is cached by memory database cache, and the thumbnail of the image is cached by browser cache and disk cache; the resource volume interval corresponding to the second category is [1MB, 10MB); the thumbnail is generated by the server after automatically performing lossy compression on the image of the second category;
[0042] If the image is of the third category and the resource size of the image is in the interval of (0, 500KB), the image is cached by browser cache and disk cache; if the image is of the third category and the resource size of the image is in the interval of [500KB, 1MB), the image is cached by browser cache and disk cache after lossless compression by the server; the resource amount interval corresponding to the third category is (0, 1MB).
[0043] The performing of the picture loading operation based on the plurality of cached sub-pictures includes:
[0044] Read multiple block resources of the client's memory database in parallel to determine whether the memory database hits the multiple sub-images;
[0045] If so, the multiple sub-images are loaded from the multiple block resources.
[0046] In an optional implementation, performing the picture loading operation based on the cached multiple sub-pictures further includes:
[0047] If the category of the picture is the second category, the original picture and the thumbnail of the picture are read in parallel in the memory database, the browser memory and the disk memory to determine whether the cache medium hits or not. If it hits, the thumbnail is loaded first and then the original picture is loaded;
[0048] If the category of the image is the third category, the image is read from the browser cache and the disk cache to determine whether the cache medium hits or not. If it hits, the image is directly loaded.
[0049] The server stores the pictures uploaded by the client and the processing results of the pictures; the method also includes:
[0050] If the image resource is not found in the cache medium, a request to read the image resource is sent to the server;
[0051] Receive a picture corresponding to the picture resource reading request provided by the server;
[0052] According to the picture corresponding to the picture resource reading request provided by the server, a picture loading operation and a cache operation are performed.
[0053] The third aspect of the present application provides a picture loading device, which includes:
[0054] The picture receiving module is used to receive the picture uploaded by the client and determine the resource size of the picture;
[0055] A picture category determination module, used to classify the picture according to the resource amount interval to which the resource size of the picture belongs, and the correspondence between multiple resource amount intervals and picture categories;
[0056] An image processing module, configured to automatically cut the image into a plurality of sub-images if the category of the image is a first category; wherein the first category is the image category corresponding to the maximum resource amount interval;
[0057] The picture sending module is used to provide the multiple sub-pictures to the client so that the client caches the multiple sub-pictures and performs a picture loading operation; wherein the way in which the client caches the multiple sub-pictures is determined based on the resource size of the sub-pictures; the way in which the client performs the picture loading operation is determined based on the resource size of the loaded picture.
[0058] A fourth aspect of the present application provides another image loading device, the device comprising:
[0059] An image uploading module, used for uploading images to a server, so that the server can classify the images according to the resource volume interval to which the resource size of the images belongs, and the correspondence between multiple resource volume intervals and categories;
[0060] The image cache module is used to receive the classification result of the image by the server, and if the image is of the first category, cache the sub-image generated after the image is automatically cropped by the server; wherein the method of caching the sub-image is determined based on the resource size of the sub-image; the first category is the image category corresponding to the largest resource amount interval;
[0061] The image loading module is used to perform an image loading operation based on multiple cached sub-images; wherein the image loading operation is determined based on the resource size of the loaded image.
[0062] Compared with the prior art, this application has the following beneficial effects:
[0063] After receiving the image, the server first classifies it according to its resource size, then processes the image accordingly according to the category, and sends the original image and the processed image back to the client for caching and loading. The image size is classified according to the actual situation, and different optimization measures such as automatic cropping and compression are taken for different categories of images, and the image and its optimized image are cached and loaded accordingly, balancing the image optimization cost and improving the image loading performance. At the same time, it can more effectively manage storage space and improve resource utilization; large resource images are automatically cut into multiple sub-images for caching and loading, which can simplify the processing process of large resource images while maintaining high image precision, and improve the smoothness of image loading through corresponding caching and loading methods, thereby improving user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0065] Figure 1 A flowchart of a method for loading an image provided in an embodiment of the present application;
[0066] Figure 2 A signaling diagram of a first category picture loading method provided in an embodiment of the present application;
[0067] Figure 3A signaling diagram of a method for loading three different types of pictures provided in an embodiment of the present application;
[0068] Figure 4 A flowchart of corresponding processing of three different types of pictures provided in an embodiment of the present application;
[0069] Figure 5 A flowchart of caching sub-pictures provided in an embodiment of the present application;
[0070] Figure 6 A flowchart of a client reading a picture cache medium provided in an embodiment of the present application;
[0071] Figure 7 A flowchart of a server reading a picture provided in an embodiment of the present application;
[0072] Figure 8 A flowchart of a picture loading process provided in an embodiment of the present application;
[0073] Fig. 9 A flowchart of another image loading method provided in an embodiment of the present application;
[0074] Fig.10 A schematic diagram of the structure of a picture loading device provided in an embodiment of the present application;
[0075] Fig.11 A schematic diagram of the structure of another image loading device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0076] As described above, the performance of image loading is generally optimized by compressing images and using browsers to cache images. There are usually two ways to compress images, namely lossy compression and lossless compression. Lossy compression achieves a higher compression ratio by reducing the size of data, which will affect the final presentation quality of the image data, especially when high-resolution rendering or applying images to professional purposes, the loss of image quality will be more obvious. Lossless compression ensures the integrity of the original data and can be fully restored after decompression. The disadvantage is that the compression ratio is limited. The browser stores the most recently requested images on the user's disk. When the visitor requests to access this image again, the browser can read the image from the user's disk, which can speed up the reading of the image. The above-mentioned image loading methods are difficult to take into account the problems of image quality, compression ratio and reading speed.
[0077] In view of the above problems, the inventor has proposed a method and device for loading pictures after research. First, the pictures are classified according to their resource size, and then the pictures are processed accordingly based on the categories, and the original pictures and processed pictures are sent back to the client for caching and loading. This solution classifies pictures according to their size, and different compression, caching and loading measures are adopted for different categories, which can balance the cost of picture optimization and improve picture loading performance, and at the same time can more effectively manage storage space and improve resource utilization; large resource pictures are automatically cut into multiple sub-pictures for caching and loading, which can simplify the processing process of large resource pictures while maintaining high picture precision, and improve the smoothness of picture loading through caching mechanism and loading mechanism, thereby improving user experience.
[0078] 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. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0079] See also Figure 1 , which is a flow chart of a method for loading an image provided by an embodiment of the present application. Figure 1 In the introduction, the implementation process of the method is mainly described from the perspective of the device running the server.
[0080] like Figure 1 As shown, the method comprises the following steps:
[0081] S101, receiving a picture uploaded by a client, and determining a resource size of the picture.
[0082] Receive one or more images uploaded from a client (such as an application on a user's computer, mobile phone, or other device) and determine the size of these images, that is, the size of the storage resources they occupy, usually in units of KB, MB, etc.
[0083] S102: Classify the picture according to the resource amount interval to which the resource size of the picture belongs, and the correspondence between multiple resource amount intervals and picture categories.
[0084] According to the specific resource amount interval of the resource size of the picture, and based on the pre-defined correspondence between resource amount intervals of different sizes and picture categories, the picture is classified into a corresponding category. In the present application, exemplarily, three resource amount intervals can be divided according to the resource size of the picture, and the three resource amount intervals correspond to three picture categories respectively, the resource amount interval corresponding to the first category is [10MB, +∞), the resource amount interval corresponding to the second category is [1MB, 10MB), and the resource amount interval corresponding to the third category is (0, 1MB).
[0085] S103: If the category of the picture is the first category, automatically cut the picture into a plurality of sub-pictures.
[0086] Among them, as described above, the first category is the image category corresponding to the largest resource amount interval. In this step, as an example, cropping is performed according to the preset data amount, for example, one sub-image is cropped for every 1MB. If the resource size of the image of the first category is not an integer multiple of the preset data amount of a single sub-image, it can also be cropped by rounding down. For example, the size of the original image uploaded by the client to the server is X, and the ratio of X to 1MB is rounded down to obtain the number C, and C is used as the number of sub-images after cropping.
[0087] S104: Provide the multiple sub-pictures to the client, so that the client caches the multiple sub-pictures and performs a picture loading operation.
[0088] The manner in which the client caches the multiple sub-images is determined based on the resource size of the sub-images; and the manner in which the client performs the image loading operation is determined based on the resource size of the loaded image.
[0089] The multiple sub-images are provided to the client, and the client decides how to cache the sub-images according to the resource sizes of the sub-images, and when loading the sub-images, the client also optimizes the loading process according to their resource sizes.
[0090] By classifying images according to their resource size, it is possible to quickly identify images of different sizes and complexities, process them accordingly based on their resource size, and determine the caching and loading methods based on actual conditions when caching and loading images, thereby increasing loading speed and managing and using storage space more efficiently. Large resource images are automatically cut into multiple sub-images, which simplifies the processing of large resource images while maintaining high image precision, and improves the loading efficiency of large resource images.
[0091] See also Figure 2 , which is a signaling diagram of a first category picture loading method provided by an embodiment of the present application. Figure 2 As shown, the method includes:
[0092] S201. The client uploads a picture.
[0093] Client uploading pictures refers to the process in which users send pictures on their local devices to the server through an application or website. This process is very common in actual application scenarios, such as users sharing photos on social media.
[0094] S202: The server receives a picture, and determines the picture as a first category according to a resource size of the picture.
[0095] Receive one or more pictures uploaded from a client (such as an application on a user's computer, mobile phone, or other device), and determine the resource size of these pictures, that is, the size of the storage resources they occupy, usually in units of KB, MB, etc., and classify the pictures into a first category according to the resource size of the pictures. The first category corresponds to the largest resource amount interval. In this application, the maximum resource amount interval is [10MB,+∞).
[0096] S203: The server automatically cuts the image into multiple sub-images, and sends the multiple sub-images to the client.
[0097] In this step, as an example, cropping is performed according to a preset data amount, for example, one sub-image is cropped for every 1MB. If the resource size of the first category of images is not an integer multiple of the preset data amount of a single sub-image, cropping can also be performed by rounding down. For example, the size of the original image uploaded by the client to the server is X, and the ratio of X to 1MB is rounded down to obtain a number C, and C is used as the number of sub-images after cropping.
[0098] Each sub-image is a block, the position of the block is marked, and a block map is generated.
[0099] S204: The client receives the multiple sub-images and caches them in a memory database, and sends them to the server for storage.
[0100] The client receives the multiple sub-images sent from the server, caches the multiple sub-images in the client's memory database for quick access and application, and sends the multiple sub-images back to the server for persistent storage. For example, in an image processing application, the client may need to frequently access the same group of sub-images for display or processing. In order to improve efficiency, these sub-images are first cached in the client's memory. At the same time, in order to prevent data loss, these sub-images are also sent back to the server for long-term storage.
[0101] S205, the client reads the memory database according to the block mapping to determine whether the cache medium hits. If it hits, the block map is loaded in parallel according to the block position mark. If it does not hit, multiple block resources of the server are read in parallel. The client loads the block map in parallel according to the block position mark and caches it.
[0102] The client searches the memory database for the corresponding cache data based on the block (sub-image) information of the image. The client checks whether the required block map (sub-image) exists in the memory database. If it does, it is called a hit. The client will load multiple block maps at the same time according to the block location information. If it does not exist, it is called a miss. The client will request these block resources from the server and load these block maps at the same time according to the block location information. Moreover, the client will cache these block maps in the memory database so that they can be directly hit the next time they are requested. Among them, the block mapping is used to associate each block of the image with its position in the memory database.
[0103] Automatically cutting large resource images into multiple sub-images for caching and loading can simplify the processing of large resource images while maintaining high image precision, and improve loading speed and user experience through caching and loading mechanisms.
[0104] See also Figure 3 , which is a signaling diagram of a method for loading three different types of pictures provided in an embodiment of the present application. Figure 3 As shown, the method includes:
[0105] S301, the client uploads a picture.
[0106] In this step, the image is sent from the client to the server through the device running the client application. When uploading images, you can upload them one by one or in groups. This application does not limit the size and specific number of uploaded images. The device running the client can be a computer, a smartphone, or a tablet computer. The user imports or takes a picture or a group of pictures through the client running on the device, clicks the "Upload" button or performs a similar operation to start the upload process.
[0107] S302: The server receives a picture, and classifies the picture according to the resource size interval to which the resource size of the picture belongs, and the correspondence between multiple resource size intervals and picture categories.
[0108] Among them, the resource amount interval corresponding to the first category is [10MB, +∞), the resource amount interval corresponding to the second category is [1MB, 10MB), and the resource amount interval corresponding to the third category is (0, 1MB).
[0109] When the server receives one or more images uploaded by the client, it checks the size of each image and classifies the images into different categories based on their resource size. There are three predefined categories and their corresponding resource size ranges, so that different caching and loading strategies can be used for different categories of images in the future.
[0110] S303: The server processes the image accordingly according to the category of the image, and sends the image and the processed image to the client.
[0111] like Figure 4 As shown in the figure, the server classifies the images according to their resource sizes and uses different processing methods. If the image is classified into the first category, the image is automatically cut into multiple sub-images; if the image is classified into the second category, the image is automatically lossily compressed to generate a thumbnail; if the image is classified into the third category and the resource size of the image is in the range of (0, 500KB), the image is not compressed; if the image is classified into the third category and the resource size of the image is in the range of [500KB, 1MB), the image is losslessly compressed.
[0112] After receiving the image, the server first classifies it according to its resource size, then processes the image accordingly according to the category, and sends the original image and the processed image back to the client. Such a classification and processing mechanism can help the server manage storage space, bandwidth, and other resources more effectively, while ensuring that the client can obtain high-quality image data. For example, for large resource images, cropping can reduce the size of a single file, making them easier to handle; for smaller images, choosing whether to compress and what type of compression to use based on their actual size can improve loading speed while ensuring image quality and save resource space.
[0113] S304: The client receives the image and the processed image and caches them.
[0114] If the category of the image is the first category, determine whether the resource size of the sub-image is in the range of [1MB, 10MB). If so, cache the sub-image using the client's memory database cache; if not, cache the sub-image using the client's browser cache and disk cache. Figure 5 As shown, it shows the process of caching the first category of pictures according to the resource size of the sub-pictures after the pictures are automatically cut into multiple sub-pictures.
[0115] If the category of the picture is the second category, the original picture of the picture is cached by using a memory database cache, and the thumbnail of the picture is cached by using a browser cache and a disk cache;
[0116] If the category of the image is the third category, determine whether to cache it according to the resource size of the image; if the resource size of the image is in the range of (0, 500KB), the client caches the image using browser cache and disk cache; if the resource size of the image is in the range of [500KB, 1MB), the client losslessly compresses the image and caches the image using browser cache and disk cache.
[0117] The client receives the original image and the image processed by the server, and decides how to cache these images according to the different categories of the images. If the image is of the first category, the image is automatically cropped into multiple sub-images, and the caching method is determined according to the size of the sub-images; if the image is of the second category, the original image and thumbnail of the image are cached in different ways; if the image is of the third category, the caching method is determined according to the size of the image resource. By using different caching methods for different categories, the client can effectively manage and optimize the use of local resources, ensuring that users can quickly access frequently used images while avoiding unnecessary storage overhead.
[0118] S305. According to the category of the image, the client reads the medium that caches the image and determines whether the cache medium is a hit. If so, a picture loading operation is performed on the image. If not, the server storage resource is read and the client performs a picture loading operation and a cache operation on the image.
[0119] like Figure 6 As shown in FIG. 1 , it shows that when the client reads the cache medium, different categories of images correspond to different cache media. If the cache medium is not hit, the process of reading the server storage resource is as follows: Figure 7 As shown, different loading methods are used for different categories of pictures, such as Figure 8 shown.
[0120] If the category of the image is the first category, the client reads the memory database to determine whether the cache medium hits, and if so, loads the block map of the image in parallel according to the block position mark; if not, reads multiple block resources of the server in parallel, and the client loads the block map of the image in parallel according to the block position mark and caches it in the memory database.
[0121] If the category of the image is the second category, the client reads the memory database, browser and disk in parallel to determine whether the cache medium is hit. If it is hit, the thumbnail of the image is loaded first and then the original image of the image is loaded; if it is not hit, the original image and thumbnail of the image on the server are read in parallel, and the client first loads the thumbnail of the image and then the original image of the image and caches the image, wherein the original image of the image is cached in the memory database, and the thumbnail of the image is cached in the browser and disk.
[0122] If the category of the image is the third category, the client reads the browser and disk to determine whether the cache medium hits, and if so, directly loads the image; if not, directly reads the image from the server, and the client directly loads and caches the image in the browser and disk.
[0123] Different image categories have different corresponding reading and loading methods. Through the previous step, you can know the cache medium of the image, and further read the cache medium to which the image belongs to determine whether the image exists in the cache medium. If it exists, it is called a hit, and the image is loaded using the corresponding loading method. If it does not exist, it is called a miss. The client will request the image resource from the server, load the image using the corresponding loading method, and cache the image resource on the client so that it can be directly hit the next time it is requested.
[0124] Images of different sizes may require different processing methods. For example, large images may require more computing resources to process, while small resource images can be processed quickly. By classifying images and formulating different management strategies for different categories of images, the overall image loading performance and resource utilization are improved.
[0125] The client reading operation involved in the above embodiment is described in detail.
[0126] If the picture is of the first category, multiple block resources of the memory database are read to determine whether the memory database hits a sub-picture of the picture.
[0127] If the picture belongs to the second category, the thumbnail of the picture in the browser cache and the disk cache is read, and the original picture of the picture in the memory database is read.
[0128] If the image is of the third category, the image in the browser cache and the disk cache is directly read.
[0129] See also Fig. 9 , which is a flow chart of another image loading method provided by an embodiment of the present application. Fig. 9 In the introduction, the implementation process of the method is mainly described from the perspective of the device running the client. Fig. 9As shown, the method includes:
[0130] S401. Upload a picture to a server, so that the server classifies the picture according to the resource size interval to which the picture belongs and the correspondence between multiple resource size intervals and picture categories.
[0131] The user or client application sends one or more pictures to the server through the network. After receiving the pictures, the server checks the resource size of the pictures, finds the corresponding resource size interval according to the resource size of the pictures, and then classifies the pictures into corresponding categories according to the corresponding relationship between the resource size interval and the picture category. This classification mechanism helps to improve processing efficiency, and can manage and use pictures in a targeted manner according to different application scenarios.
[0132] S402, receiving the classification result of the image by the server, and if the image belongs to the first category, caching the sub-image generated by the image after automatic cropping by the server.
[0133] The manner of caching the sub-image is determined based on the resource size of the sub-image; and the first category is the image category corresponding to the largest resource amount interval.
[0134] The server classifies the image resources according to their size. If the image belongs to the first category, the server automatically cuts the image to generate a sub-image. The client receives the sub-image and caches it. The sub-image resource size is different, and the cache method used is different. The cache refers to temporarily storing the sub-image for quick access or further processing. Through this method, the storage and transmission of large images can be effectively managed and optimized, and the user experience can be improved.
[0135] S403: Perform a picture loading operation based on the cached multiple sub-pictures.
[0136] The manner of the picture loading operation is determined based on the resource size of the loaded picture.
[0137] The image loading operation is performed on the sub-image, and the resource size of the sub-image is different, and the image loading method adopted is also different. The loading refers to reading the image from the cache or other storage medium into the memory for display or further processing. The loading process is optimized according to the resource size of the image, thereby improving the user experience and the response speed of the system.
[0138] Classify images according to their resource size, and adopt different caching and loading methods for different categories of images. This classification strategy helps to improve the image loading speed and reduce user waiting time; automatically cut large images into sub-images, cache and load them according to their resource size. This method can effectively manage and optimize the storage and transmission of large images and improve user experience.
[0139] Based on the image loading method introduced in the previous embodiment, accordingly, an embodiment of the present application provides an image loading device. Fig.10 Figure 1 is a schematic diagram of the structure of the device. Fig.10 As shown, the image loading device includes:
[0140] The picture receiving module 1001 is used to receive the picture uploaded by the client and determine the resource size of the picture;
[0141] A picture category determination module 1002, configured to classify the picture according to the resource amount interval to which the resource size of the picture belongs, and the correspondence between multiple resource amount intervals and picture categories;
[0142] The picture processing module 1003 is used to automatically cut the picture into a plurality of sub-pictures if the category of the picture is the first category; wherein the first category is the picture category corresponding to the maximum resource amount interval;
[0143] The picture sending module 1004 is used to provide the multiple sub-pictures to the client so that the client caches the multiple sub-pictures and performs a picture loading operation; wherein, the way in which the client caches the multiple sub-pictures is determined based on the resource size of the sub-pictures; the way in which the client performs the picture loading operation is determined based on the resource size of the loaded picture.
[0144] The image processing module is specifically used for: if the category of the image is the first category, and the resource amount interval corresponding to the first category is [10MB, +∞), the image processing module is also used for: if the category of the image is the second category, automatically lossy compressing the image to generate a thumbnail; the resource amount interval corresponding to the second category is [1MB, 10MB); if the category of the image is the third category, and the resource size of the image is in the interval (0, 500KB), then the image is not compressed; if the category of the image is the third category, and the resource size of the image is in the interval [500KB, 1MB), then the image is losslessly compressed.
[0145] The picture sending module is specifically used to provide the cropped sub-picture of the picture to the client if the category of the picture is the first category. The picture sending module is also used to: if the category of the picture is the second category, provide the original picture and the thumbnail generated by automatic lossy compression to the client; if the category of the picture is the third category and the resource size of the picture is in the range of (0, 500KB), directly send the picture to the client; if the category of the picture is the third category and the resource size of the picture is in the range of [500KB, 1MB), compress the picture losslessly and send it to the client.
[0146] Another image loading device is provided in an embodiment of the present application. Fig.11 Figure 1 is a schematic diagram of the structure of the device. Fig.11 As shown, the image loading device includes:
[0147] The picture uploading module 1101 is used to upload pictures to the server, so that the server can classify the pictures according to the resource amount interval to which the resource size of the pictures belongs and the correspondence between multiple resource amount intervals and categories;
[0148] The image cache module 1102 is used to receive the classification result of the image by the server, and if the image is of the first category, cache multiple sub-images generated after the image is automatically cropped by the server; wherein the method of caching the multiple sub-images is determined based on the resource size of the sub-images; the first category is the image category corresponding to the largest resource amount interval;
[0149] The picture loading module 1103 is used to perform a picture loading operation based on the cached multiple sub-pictures; wherein the picture loading operation is determined based on the resource size of the loaded picture.
[0150] The image cache module is specifically used to determine whether the resource size of the sub-image is within the range of [1MB, 10MB). If so, the sub-image is cached using a memory database cache;
[0151] If not, the sub-image is cached using browser cache and disk cache.
[0152] The image cache module is also used to cache the original image of the image by memory database cache, and cache the thumbnail of the image by browser cache and disk cache if the image belongs to the second category; the resource volume interval corresponding to the second category is [1MB, 10MB); the thumbnail is generated by the server after automatically performing lossy compression on the image of the second category;
[0153] If the image is of the third category and the resource size of the image is in the interval of (0, 500KB), the image is cached by browser cache and disk cache; if the image is of the third category and the resource size of the image is in the interval of [500KB, 1MB), the image is cached by browser cache and disk cache after lossless compression by the server; the resource amount interval corresponding to the third category is (0, 1MB).
[0154] The image loading module is specifically used to read multiple block resources of the client's memory database in parallel to determine whether the memory database hits the multiple sub-images; if so, load the multiple sub-images from the multiple block resources.
[0155] The picture loading module is also used for, if the category of the picture is the second category, reading the original picture and the thumbnail of the picture in parallel from the memory database, the browser memory and the disk memory, judging whether the cache medium hits or not, and if so, loading the thumbnail first and then the original picture;
[0156] If the category of the image is the third category, the image is read from the browser cache and the disk cache to determine whether the cache medium hits or not. If it hits, the image is directly loaded.
[0157] The image loading device further includes: if the image resource is not hit in the cache medium, sending an image resource reading request to the server;
[0158] Receive a picture corresponding to the picture resource reading request provided by the server;
[0159] According to the picture corresponding to the picture resource reading request provided by the server, a picture loading operation and a cache operation are performed.
[0160] It should be noted that each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely schematic, in which the unit described as a separate component may or may not be physically separated, and the component prompted as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the modules can 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 work.
[0161] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for loading an image, characterized in that: include: Receive the picture uploaded by the client and determine the resource size of the picture; Classifying the picture according to the resource amount interval to which the resource size of the picture belongs, and the correspondence between multiple resource amount intervals and picture categories; If the category of the picture is the first category, the picture is automatically cut into a plurality of sub-pictures; wherein the first category is the picture category corresponding to the largest resource amount interval; The multiple sub-pictures are provided to the client so that the client caches the multiple sub-pictures and performs a picture loading operation; wherein the manner in which the client caches the multiple sub-pictures is determined based on the resource size of the sub-pictures; and the manner in which the client performs the picture loading operation is determined based on the resource size of the loaded picture.
2. The method according to claim 1, characterized in that The resource amount interval corresponding to the first category is [10MB, +∞); the method further includes: If the category of the picture is the second category, the picture is automatically lossily compressed to generate a thumbnail; the resource amount interval corresponding to the second category is [1MB, 10MB); If the category of the picture is the third category and the resource size of the picture is in the range of (0, 500KB), the picture is not compressed; If the category of the image is the third category and the resource size of the image is in the interval [500KB, 1MB), the image is losslessly compressed; the resource size interval corresponding to the third category is (0, 1MB).
3. The method according to claim 1, characterized in that The client caches the multiple sub-images in the following manner: Determine whether the resource size of the sub-image is in the range of [1MB, 10MB). If so, cache the sub-image using the client's memory database cache. If not, the sub-image is cached using the client's browser cache and disk cache.
4. The method according to claim 2, characterized in that: Also includes: If the category of the picture is the second category, providing the picture to the client, so that the client caches the picture and performs a picture loading operation; The original image of the image is cached by a client's memory database cache, and the thumbnail of the image is cached by a browser cache and a disk cache; If the category of the picture is the third category, the picture is provided to the client, so that the client determines whether to cache according to the resource size of the picture, and performs a picture loading operation; wherein, if the resource size of the picture is in the interval of (0, 500KB), the client caches the picture by browser cache and disk cache; if the resource size of the picture is in the interval of [500KB, 1MB), the picture is losslessly compressed, and the client caches the losslessly compressed picture by browser cache and disk cache.
5. The method according to claim 1, characterized in that The client performs the image loading operation in the following manner: Read multiple block resources of the client's memory database in parallel to determine whether the memory database hits the multiple sub-images; If so, the multiple sub-images are loaded from the multiple block resources.
6. The method according to claim 4, characterized in that Also includes: If the category of the picture is the second category, the client reads the original picture and thumbnail of the picture in parallel from the client's memory database, browser cache and disk cache, and determines whether the cache medium hits or not. If it hits, the thumbnail is loaded first and then the original picture; If the category of the image is the third category, the client reads the image from the browser cache and disk cache of the client, determines whether the cache medium hits or not, and if so, directly loads the image.
7. The method according to claim 5 or 6, characterized in that: Also includes: The server stores the pictures uploaded by the client and the processing results of the pictures; The server, in response to the picture resource reading request of the client, provides the client with a picture corresponding to the picture resource reading request; The picture resource read request is generated by the client and sent to the server under the condition that the picture resource is not found in the cache medium.
8. A method for loading an image, characterized in that: include: Uploading the image to the server, so that the server classifies the image according to the resource size interval to which the resource size of the image belongs and the correspondence between the multiple resource size intervals and the image categories; Receive the classification result of the image by the server, and if the image is of the first category, cache multiple sub-images generated after the image is automatically cropped by the server; wherein the manner of caching the multiple sub-images is determined based on the resource size of the sub-images; the first category is the image category corresponding to the largest resource amount interval; An image loading operation is performed based on multiple cached sub-images; wherein the image loading operation is performed in a manner determined based on a resource size of the loaded image.
9. The method according to claim 8, characterized in that The method of caching the sub-image generated after the image is automatically cropped by the server is: Determine whether the resource size of the sub-image is in the range of [1MB, 10MB). If so, cache the sub-image using the memory database cache method; If not, the sub-image is cached using browser cache and disk cache.
10. The method according to claim 8, characterized in that The resource amount interval corresponding to the first category is [10MB, +∞); the method further includes: If the image is of the second category, the original image of the image is cached by memory database cache, and the thumbnail of the image is cached by browser cache and disk cache; the resource volume interval corresponding to the second category is [1MB, 10MB); the thumbnail is generated by the server after automatically performing lossy compression on the image of the second category; If the image is of the third category and the resource size of the image is in the interval of (0, 500KB), the image is cached by browser cache and disk cache; if the image is of the third category and the resource size of the image is in the interval of [500KB, 1MB), the image is cached by browser cache and disk cache after lossless compression by the server; the resource amount interval corresponding to the third category is (0, 1MB).
11. The method according to claim 8, characterized in that The performing of the picture loading operation based on the plurality of cached sub-pictures includes: Read multiple block resources of the client's memory database in parallel to determine whether the memory database hits the multiple sub-images; If so, the multiple sub-images are loaded from the multiple block resources.
12. The method according to claim 10, characterized in that Also includes: If the category of the picture is the second category, the original picture and the thumbnail of the picture are read in parallel in the memory database, the browser memory and the disk memory to determine whether the cache medium hits or not. If it hits, the thumbnail is loaded first and then the original picture is loaded; If the category of the image is the third category, the image is read from the browser cache and the disk cache to determine whether the cache medium hits or not. If it hits, the image is directly loaded.
13. The method according to claim 11 or 12, characterized in that: The server stores the pictures uploaded by the client and the processing results of the pictures; the method also includes: If the image resource is not found in the cache medium, a request to read the image resource is sent to the server; Receive a picture corresponding to the picture resource reading request provided by the server; According to the picture corresponding to the picture resource reading request provided by the server, a picture loading operation and a cache operation are performed.
14. A picture loading device, characterized in that: include: The picture receiving module is used to receive the picture uploaded by the client and determine the resource size of the picture; A picture category determination module, used to classify the picture according to the resource amount interval to which the resource size of the picture belongs, and the correspondence between multiple resource amount intervals and picture categories; An image processing module, configured to automatically cut the image into a plurality of sub-images if the category of the image is a first category; wherein the first category is the image category corresponding to the maximum resource amount interval; The picture sending module is used to provide the multiple sub-pictures to the client so that the client caches the multiple sub-pictures and performs a picture loading operation; wherein the way in which the client caches the multiple sub-pictures is determined based on the resource size of the sub-pictures; the way in which the client performs the picture loading operation is determined based on the resource size of the loaded picture.
15. A picture loading device, characterized in that: include: An image uploading module, used for uploading images to a server, so that the server can classify the images according to the resource volume interval to which the resource size of the images belongs, and the correspondence between multiple resource volume intervals and categories; The image cache module is used to receive the classification result of the image by the server, and if the image is of the first category, cache multiple sub-images generated after the image is automatically cropped by the server; wherein the method of caching the multiple sub-images is determined based on the resource size of the sub-images; the first category is the image category corresponding to the largest resource amount interval; The image loading module is used to perform an image loading operation based on multiple cached sub-images; wherein the image loading operation is determined based on the resource size of the loaded image.
Citation Information
Patent Citations
Image loading method and device
CN105335526A
Picture loading method of Android system
CN111931095A
Picture loading method and device, equipment and storage medium
CN114996606A