Picture loading method and device, computer device and storage medium
Patent Information
- Application Number
- CN202210358918.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2042-04-07
AI Technical Summary
但是,Flutter在每次加载图片时都需要执行解码-渲染两个步骤,因此,图片的加载速度受到了机器性能、以及图片大小的影响;如果Flutter在加载重复图片时,此时若系统缓存已销毁,那么该图片将会重新执行解码步骤,从而无法保证图片加载的速度
[0035] The aforementioned image loading method, apparatus, computer device, storage medium, and computer program product, after obtaining an image loading request, first search for the image decoding data corresponding to the image loading request locally; when the image decoding data corresponding to the image loading request is not found, decode the target image indicated by the image loading request and cache the decoded image data; when the image decoding data corresponding to the image loading request is found, obtain the image decoding data from the locally cached data; and perform rendering and loading processing on the target image based on the image decoding data. This application can decode the target image indicated by the image loading request and cache it when the image decoding data corresponding to the image loading request is not found, for use in subsequent rendering and loading processes. When the image decoding data is cached locally, the target image is directly rendered and loaded based on the decoded data. Therefore, when the image decoding data is cached locally, the decoding process in the image loading process can be skipped directly, thereby comprehensively improving the image loading speed.
Smart Images

Figure CN116932490B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an image loading method, apparatus, computer device, storage medium, and computer program product. Background Technology
[0002] With the continuous development of internet technology, various application software has emerged, bringing convenience to people's work and life. Each application software needs to load corresponding images for its user interface when running. By drawing and rendering these loaded images, the corresponding user interface can be displayed.
[0003] When developing application software, cross-platform UI development frameworks can be used to create user interfaces. These frameworks can be applied to different operating systems. For example, the existing Flutter framework provides an image loading component that can build native user interfaces on different operating systems. However, Flutter requires two steps—decoding and rendering—each time an image is loaded. Therefore, image loading speed is affected by machine performance and image size. If Flutter loads a duplicate image and the system cache has been destroyed, the decoding process will be repeated, thus compromising loading speed. Summary of the Invention
[0004] Therefore, it is necessary to provide an image loading method, apparatus, computer device, computer-readable storage medium, and computer program product that can improve image loading speed in response to the above-mentioned technical problems.
[0005] Firstly, this application provides an image loading method. The method includes:
[0006] Get the image loading request;
[0007] Find the image decoding data corresponding to the image loading request locally;
[0008] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the image decoding data obtained by decoding is cached.
[0009] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0010] The target image is rendered and loaded based on the image decoding data.
[0011] Secondly, this application also provides an image loading device. The device includes:
[0012] The request retrieval module is used to retrieve image loading requests.
[0013] The decoding data lookup module is used to find the image decoding data corresponding to the image loading request locally;
[0014] The first data acquisition module is used to decode the target image indicated by the image loading request and cache the decoded image data when no image decoding data corresponding to the image loading request is found.
[0015] The second data acquisition module is used to obtain the image decoding data from the local cache data when the image decoding data corresponding to the image loading request is found.
[0016] The image loading module is used to render and load the target image based on the image decoding data.
[0017] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0018] Get the image loading request;
[0019] Find the image decoding data corresponding to the image loading request locally;
[0020] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the image decoding data obtained by decoding is cached.
[0021] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0022] The target image is rendered and loaded based on the image decoding data.
[0023] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0024] Get the image loading request;
[0025] Find the image decoding data corresponding to the image loading request locally;
[0026] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the image decoding data obtained by decoding is cached.
[0027] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0028] The target image is rendered and loaded based on the image decoding data.
[0029] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0030] Get the image loading request;
[0031] Find the image decoding data corresponding to the image loading request locally;
[0032] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the image decoding data obtained by decoding is cached.
[0033] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0034] The target image is rendered and loaded based on the image decoding data.
[0035] The aforementioned image loading method, apparatus, computer device, storage medium, and computer program product, after obtaining an image loading request, first search for the image decoding data corresponding to the image loading request locally; when the image decoding data corresponding to the image loading request is not found, decode the target image indicated by the image loading request and cache the decoded image data; when the image decoding data corresponding to the image loading request is found, obtain the image decoding data from the locally cached data; and perform rendering and loading processing on the target image based on the image decoding data. This application can decode the target image indicated by the image loading request and cache it when the image decoding data corresponding to the image loading request is not found, for use in subsequent rendering and loading processes. When the image decoding data is cached locally, the target image is directly rendered and loaded based on the decoded data. Therefore, when the image decoding data is cached locally, the decoding process in the image loading process can be skipped directly, thereby comprehensively improving the image loading speed. Attached Figure Description
[0036] Figure 1 This is a schematic diagram illustrating the application environment of the image loading method in one embodiment;
[0037] Figure 2 This is a flowchart illustrating an image loading method in one embodiment;
[0038] Figure 3 This is a flowchart illustrating the image loading method in another embodiment;
[0039] Figure 4 This is a flowchart illustrating the image loading method in yet another embodiment;
[0040] Figure 5 This is a schematic diagram showing the memory usage of an image before loading, without using the memory loading method of this application in one embodiment.
[0041] Figure 6 This is a schematic diagram illustrating the memory usage after image loading in an embodiment where the memory loading method of this application is not used.
[0042] Figure 7 This is a schematic diagram illustrating the memory usage before image loading using the memory loading method of this application in one embodiment.
[0043] Figure 8 This is a schematic diagram illustrating the memory usage after image loading using the memory loading method of this application in one embodiment;
[0044] Figure 9 This is a structural block diagram of an image loading device in one embodiment;
[0045] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0046] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0047] The image loading method provided in this application embodiment can be applied to, for example... Figure 1 In the application environment shown, terminal 102 is equipped with an operating system that can load images in response to user operations. When a user on terminal 102 needs to load an image, they can trigger an image loading request on terminal 102 by operating the terminal. First, terminal 102 obtains the image loading request; it searches for the image decoding data corresponding to the image loading request locally; if the image decoding data corresponding to the image loading request is not found, it decodes the target image indicated by the image loading request and caches the resulting image decoding data; when the image decoding data corresponding to the image loading request is found, it obtains the image decoding data from the local cache data; and it performs rendering and loading processing on the target image based on the image decoding data. Thus, as shown... Figure 1As shown in the right figure, the corresponding image is loaded on terminal 102. The terminal can be, but is not limited to, various desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle systems, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc.
[0048] In one embodiment, such as Figure 2 As shown, an image loading method is provided. This embodiment applies this method to... Figure 1 Taking terminal 102 as an example, in this embodiment, the method includes the following steps:
[0049] Step 201: Obtain the image loading request.
[0050] The image loading request is used to request the terminal to load the corresponding image content. The image loading request may contain indication data of the target image, which can be a local image or a network image.
[0051] Specifically, the image loading method of this application is applied when a user needs to load an image. If the image requires both decoding and rendering steps, the image loading method of this application can accelerate image generation. First, the user can generate an image loading request by operating the terminal, for example, by clicking a corresponding button on the terminal to notify the terminal to perform an image loading operation. In one embodiment, the terminal can use the Flutter framework to perform the loading operation of the target image based on the image loading request. Flutter is an open-source user interface toolkit that helps developers efficiently build beautiful multi-platform applications with a single codebase, supporting mobile, web, desktop, and embedded platforms. Users can use the Flutter framework to load images in the user interface. Flutter needs to perform both decoding and rendering steps each time it loads an image; therefore, the image loading speed is affected by machine performance and image size. If Flutter loads a duplicate image and the system cache has been destroyed, the image will undergo the decoding step again. Therefore, the image loading method of this application can be used to perform image loading processing under the Flutter framework, thereby improving the image loading speed.
[0052] Step 203: Locate the image decoding data corresponding to the image loading request locally.
[0053] Decoding refers to the process of using specific methods to restore digital data to its represented content or to convert electrical pulse signals, optical signals, radio waves, etc., into the information or data they represent. Decoding is the process by which the receiver restores received symbols or codes into information, corresponding to the encoding process. In the scheme of this application, decoding is mainly used to decode target images obtained from local storage or the network. The obtained result is image decoding data, which, after rendering processing, can be displayed on the terminal's display page.
[0054] Specifically, when the image loading method of this application obtains an image loading request, it first looks up the image decoding data corresponding to the image loading request locally, instead of directly decoding the target image. This way, when the image decoding data is stored locally, there is no need to perform repeated decoding. Instead, the image decoding data obtained from the local cache is directly used for rendering, thereby improving the efficiency of image loading.
[0055] Step 205: When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the decoded image data is cached.
[0056] Step 207: When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data.
[0057] The target image refers to the image that needs to be loaded for image loading in this application. The target image can be a local image or a network image.
[0058] Specifically, since the local machine may or may not store the image decoding data for the target wood chip indicated by the image loading request, two branches of operations need to be executed depending on whether the image decoding data corresponding to the image loading request can be found locally. If the image decoding data is not found, it means the target image's decoding data is not stored locally. In this case, the target image indicated by the image loading request needs to be decoded to obtain its decoding data for image loading. After caching the decoded image data, to ensure efficient loading of the target image next time, it can be cached locally for subsequent loading processes. Conversely, if the image decoding data corresponding to the image loading request can be directly found locally, it can be cached directly from the local cache, saving decoding time required when the image is reloaded.
[0059] Step 209: Render and load the target image based on the image decoding data.
[0060] Rendering refers to the operation of displaying images on the terminal screen based on the image decoding data obtained from graphics decoding.
[0061] Specifically, after the image decoding data obtained from the cache decoding is completed, the final rendering operation can be performed. The rendering process allows the target image to be directly loaded onto the terminal's display interface for display. In one embodiment, the rendering loading process specifically includes: obtaining the image coordinates through the terminal's graphics processing unit (GPU), passing the coordinates to the vertex shader (vertex calculation), image rasterization (obtaining the corresponding pixels on the screen), fragment shader calculation (calculating the final displayed color value for each pixel), and rendering from the frame buffer to the screen. Through the above process, the target image can be effectively displayed on the terminal's display interface.
[0062] The above image loading method, after obtaining an image loading request, first searches for the image decoding data corresponding to the image loading request locally; when no image decoding data is found, the target image indicated by the image loading request is decoded, and the decoded image data is cached; when image decoding data is found, the image decoding data is obtained from the local cache; and the target image is rendered and loaded based on the image decoding data. This application can decode the target image indicated by the image loading request and cache it when no image decoding data is found, for use in subsequent rendering and loading processes. When image decoding data is cached locally, the target image is directly rendered and loaded based on the decoded data, thus skipping the decoding process during image loading when image decoding data is cached locally, thereby comprehensively improving the image loading speed. In one embodiment, as shown... Figure 3 As shown, step 205 includes:
[0063] Step 302: Based on the image loading request, find the image component and obtain the preset image provider class in the image component.
[0064] Step 304: Based on the preset image provider class, obtain the image decoding data corresponding to the target image through the image stream listener manager, and cache the image decoding data obtained from decoding.
[0065] The Image component is used to display images. It has multiple constructors: `new Image` (gets an image from an ImageProvider), `new Image.asset` (loads a resource image), `new Image.file` (loads a local image file), `new Image.network` (loads a network image), and `new Image.memory` (loads a Uint8List of resource images). The default image provider class, `ImageProvider`, is an abstract class under the `image` property of the Image component, used to implement image data acquisition. The ImageStreamCompleter is used to parse the image frame by frame to obtain the corresponding image decoding data.
[0066] Specifically, when decoding the target image corresponding to the image loading request and obtaining the image decoding data, an image component can be used to implement the image decoding process. When using this component, the image provider class passed in is set to a custom preset image provider class, ImageProvider. This custom ImageProvider obtains the decoded image data by overriding the image stream listener manager, ImageStreamCompleter, and then caches the decoded image data locally for subsequent processing. The ImageStreamCompleter specifically executes image decoding using the image stream loading method load(AssetBundleImageKey key, decode) to obtain the decoded image data. In this embodiment, by using the preset image provider class in the image component to call the image stream listener manager to perform image decoding, the image decoding data can be obtained efficiently. Simultaneously, the decoded image data is saved locally for use in subsequent image loading processes, improving the image loading efficiency of subsequent processes.
[0067] In one embodiment, if the preset image provider class inherits from the local image resource class, then step 304 includes: obtaining an image stream listener manager instance through the local image resource class; generating an image stream listener that matches the image stream listener manager instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0068] The `AssetImage` class is used to retrieve local image resources. For example, when loading a local image through Flutter, `AssetImage` will determine the appropriate image from the `AssetBundle` based on the context. `AssetBundle` is a collection of resources for a Flutter application. The image stream listener refers to a custom `ImageStreamListener`. The image stream listener can override the `onImage` event to obtain the corresponding image decoding data.
[0069] Specifically, when loading local images, the default image provider inherits from the local image resource class AssetImage. Therefore, during decoding, the image stream loading method `load(AssetBundleImageKey key, decode)` of the local image resource class AssetImage can be called first to obtain an instance of the image stream listener manager ImageStreamCompleter. Then, the listener generation method `void addListener(ImageStreamListener listener)` of the image stream listener manager instance can be called to add a custom image stream listener ImageStreamListener. Afterward, the image decoding data corresponding to the target image can be obtained based on the generated image stream listener. In this embodiment, building and generating the image stream listener based on the obtained image stream listener manager instance to decode the local target image effectively ensures the efficiency and reliability of the target image decoding.
[0070] In one embodiment, if the preset image provider class inherits from the network image resource class, then step 304 includes: obtaining an image stream listener manager instance through the network image resource class; generating an image stream listener that matches the image stream listener manager instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0071] The NetworkImage class is a class that can download images from the network. Image.network is a wrapper around NetworkImage; it takes a URL (Uniform Resource Locator) address as input and returns an Image object. NetworkImage is similar to AssetImage.
[0072] Specifically, when loading network images, the default image provider inherits from the NetworkImage class. Therefore, during decoding, similar to decoding local images, the `load(AssetBundleImageKey key, decode)` method of the NetworkImage class is first called to obtain an instance of the ImageStreamCompleter instance. Then, the `void addListener(ImageStreamListener listener)` method of the ImageStreamCompleter instance is called to add a custom ImageStreamListener. Finally, the image decoding data corresponding to the target image can be obtained based on the generated ImageStreamListener. In this embodiment, building and generating the ImageStreamListener based on the obtained ImageStreamListener instance to decode the network target image effectively ensures the efficiency and reliability of the target image decoding.
[0073] In one embodiment, obtaining image decoding data corresponding to a target image based on an image stream listener includes:
[0074] The image stream listener executes the image listening event corresponding to the target image.
[0075] When the image listening event is called back, the image information instance generated by decoding the target image is obtained based on the callback result.
[0076] Obtain the image decoding data corresponding to the target image based on the image information instance.
[0077] Among them, the image listener event refers to the onImage listener. When the image listener event is called back, the corresponding image information instance after image decoding can be obtained. The image information instance is the ImageInfo instance, also known as basic image information, which includes information such as image format, image size, and color model.
[0078] Specifically, when obtaining image decoding data corresponding to the target image through the image stream listener manager, the image listening event can be overridden using a custom image stream listener (ImageStreamListener). This allows for the direct generation of the image information instance generated from the target image decoding based on the callback result when the subsequent image listening event is called back. The image information instance contains the image decoding data, so it can be directly read to obtain the image decoding data corresponding to the target image. In this embodiment, executing the image listening event corresponding to the target image through the image stream listener effectively generates an image information instance based on the event callback result, thereby obtaining valid image decoding data and ensuring the effectiveness of the image decoding process.
[0079] In one embodiment, step 306 includes:
[0080] When the image decoding data type that matches the image information instance is a byte data type, obtain the image decoding data of the byte data type corresponding to the target image.
[0081] Based on the decoding data conversion relationship that matches the image information instance, the image decoding data of byte data type is converted into image decoding data of integer list type.
[0082] Use the image decoding data, which is a list of integers, as the image decoding data corresponding to the target image.
[0083] In this application, the byte data type is ByteData, and the integer list type is Uint8List. Since the solution needs to save the image decoding data locally, the image decoding data of the byte data type needs to be digitally converted to obtain the image decoding data of the integer list type, and then the image decoding data of the integer list type is saved to the local disk through the corresponding interface.
[0084] Specifically, this application addresses the process of obtaining image decoding data corresponding to a target image from an image information instance. First, image decoding data of byte data type can be directly obtained from the image information instance. This can be achieved through a matching search; when the image decoding data type matching the image information instance is of byte data type, this portion of byte data type image decoding data is directly obtained. In one embodiment, the image decoding data of type ByteData can be obtained through the image decoding data acquisition method `toByteData()` of the image information instance's `image` attribute. Then, to facilitate saving this data to the terminal's local disk, after obtaining the byte data type image decoding data, based on the decoding data conversion relationship matching the image information instance, specifically by calling the ByteData decoding data conversion method `asUint8List()`, this portion of byte data type image decoding data can be converted into integer list type image decoding data. Finally, the integer list type image decoding data is written to the local disk cache for storage. In this embodiment, by obtaining byte data type image decoding data from the image information instance and then converting it into integer list type image decoding data through decoding data conversion, the image decoding data can be effectively saved to the local disk.
[0085] In one embodiment, when the image decoding data corresponding to the image loading request is found, obtaining the image decoding data from the local cache data includes: obtaining image decoding data of an integer list type through byte synchronization reading.
[0086] The rendering and loading process for the target image based on the image decoding data includes: converting the image decoding data, which is a list of integers, into an image object through pixel decoding; and then rendering and loading the target image using the original image rendering component based on the image object.
[0087] The process involves several key components: byte-synchronous reading (using the file system's `readAsBytesSync()` method to read a list of integers representing image decoding data from the local disk), pixel-decoding (using the `decodeImageFromPixels` method to convert the resulting list of integers into an `Image` object), and the raw image rendering component, `RawImage`. Its properties include `Texture`, `Color`, `Material`, `RaycastTarget`, and `UV Rect`. `Texture` specifies the image to be displayed; `Color` sets the main color; `Material` sets the rendering material of the `Image` control; `RaycastTarget` determines whether ray collision detection is supported (unchecking this option prevents it from blocking underlying UI events); `UV Rect` allows a portion of the image to be displayed within the `RawImage` component; `x` and `y` properties control the left / right and up / down UV offsets; and `w` and `h` control the number of UV repetitions. The raw image rendering component renders the image object, displaying the target image on the terminal's display page.
[0088] Specifically, when rendering and loading a target image based on image decoding data, the image decoding data needs to be converted into an image object first. If the image decoding data is stored on the local disk, the file system's `readAsBytesSync()` method (a byte-synchronous reading method) is used to read the corresponding integer list type of image decoding data from the local disk. Then, the target image can be rendered and loaded based on this image decoding data. During the loading process, the pixel decoding method `decodeImageFromPixels` first converts the integer list type of image decoding data into an image object. Then, for the image object, the raw image rendering component `RawImage` can be used directly to render and load the target image, thereby displaying the target image on the terminal page. This completes the entire image loading process. When the image decoding data corresponding to the image loading request is not found, the target image indicated by the image loading request is decoded, the obtained image decoding data is cached, and then directly converted into an image object for rendering. In this embodiment, by reading, converting, and rendering image data, image decoding data can be effectively stored locally, and the image decoding data can be quickly converted into the target image displayed on the terminal page, ensuring the speed of image display.
[0089] This application also provides an application scenario in which the above-described image loading method is applied. Specifically, the image loading method is applied in this scenario as follows:
[0090] When a user loads an image using the Flutter framework through the user interface on the terminal, the loading speed is affected by machine performance and image size because Flutter needs to perform two steps—decoding and rendering—each time an image is loaded. If Flutter loads a duplicate image and the system cache has been destroyed, the decoding step will be performed again. Therefore, the image decoding method in this application can ensure processing efficiency. A diagram illustrating the image loading process can be found here. Figure 4As shown, during the loading process, when the terminal receives an image loading request submitted by the user, it first searches for the corresponding image decoding data locally. Since this is the first time the target image is loaded, the corresponding image decoding data cannot be found locally. Therefore, the target image indicated by the image loading request is decoded, and the resulting image decoding data is cached. During decoding, if the target image is a local image, an image component can be used. When using this component, the ImageProvider class passed in is set to a custom image provider class (in this case, for local image loading, it directly inherits from the local image class AssetImage). This custom image provider class obtains and caches the decoded image data by overriding the image stream loading method load(AssetBundleImageKey key, decode) of the ImageStreamCompleter image stream listener. The process of obtaining image decoding data is as follows: First, the image stream loading method of the parent class (i.e., the local image resource class AssetImage) is called to obtain an instance of the image stream listener manager. Then, the listener addition method of this instance is called to add a custom image stream listener. This custom image stream listener overrides the image listening event, and when the image listening event is called, the corresponding image information instance after image decoding can be obtained. The byte data acquisition method toByteData() of the image information instance property image is called to obtain the image decoding data of byte data type. Then, the decoding data conversion method asUint8List() is called to convert the image decoding data of byte data type into data of integer list type (Uint8List type). Finally, the Uint8List type image decoding data is written to the disk cache. At the same time, image loading processing can also be performed. This process mainly calls the pixel decoding image method decodeImageFromPixels to convert the image decoding data into an image object. Finally, the raw image rendering component RawImage is used to render the generated image object, thereby rendering and displaying the target image on the terminal page. If the image is loaded subsequently, the image decoding data (an integer list type) can be directly obtained from the disk and then converted into an image object. The target image can then be rendered and loaded using the original image rendering component. Using the image loading method described in this application significantly reduces the reloading time of images loaded in Flutter. Taking a 4032*3024 image as an example, experiments show that before using this solution, the Flutter image loading component took approximately 309 milliseconds from component construction to image rendering; however, using this method reduces this time to approximately 139 milliseconds, a reduction of about 55%.Furthermore, using the proposed solution will reduce the memory usage for image loading. Again, using the above image as an example: before using this method, refer to... Figure 5 as well as Figure 6 The memory required for image loading increased from 159MB to 312MB; however, after using the method described in this application, referring to... Figure 7 as well as Figure 8 The memory usage for image loading increased from 159MB to 272MB. Since the image decoding process is omitted in this application, the system memory occupied by this process is also reduced, thus effectively reducing memory consumption during image loading.
[0091] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0092] Based on the same inventive concept, this application also provides an image loading apparatus for implementing the image loading method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more image loading apparatus embodiments provided below can be found in the limitations of the image loading method described above, and will not be repeated here.
[0093] In one embodiment, such as Figure 9 As shown, an image loading device is provided, including: a request acquisition module 902, a decoded data lookup module 904, a first data acquisition module 906, a second data acquisition module 908, and an image loading module 910, wherein:
[0094] The request module 902 is used to retrieve image loading requests.
[0095] The decoding data lookup module 904 is used to find the image decoding data corresponding to the image loading request locally.
[0096] The first data acquisition module 906 is used to decode the target image indicated by the image loading request and cache the decoded image data when no image decoding data corresponding to the image loading request is found.
[0097] The second data acquisition module 908 is used to obtain the image decoding data from the local cache data when the image decoding data corresponding to the image loading request is found.
[0098] Image loading module 910 is used to render and load target images based on image decoding data.
[0099] The aforementioned image loading device, after obtaining an image loading request, first searches for the corresponding image decoding data locally. If no image decoding data is found, the target image indicated by the image loading request is decoded, and the decoded image data is cached. If image decoding data is found, it is retrieved from the local cache. The target image is then rendered and loaded based on the decoded image data. This application can decode and cache the target image indicated by the image loading request when no image decoding data is found, for use in subsequent rendering and loading processes. When image decoding data is cached locally, the target image is directly rendered and loaded based on the decoded data. This allows skipping the decoding process during image loading when image decoding data is cached locally, thereby improving the overall image loading speed.
[0100] In one embodiment, the first data acquisition module 906 is specifically used to: search for an image component based on an image loading request, obtain a preset image provider class in the image component; and, based on the preset image provider class, obtain image decoding data corresponding to the target image through an image stream listener manager, and cache the image decoding data obtained from decoding.
[0101] In one embodiment, the preset image provider class inherits from the local image resource class, and the first data acquisition module 906 is specifically used to: obtain an image stream listener manager instance through the local image resource class; generate an image stream listener that matches the image stream listener manager instance; and obtain image decoding data corresponding to the target image based on the image stream listener.
[0102] In one embodiment, the preset image provider class inherits from the network image resource class, and the first data acquisition module 906 is specifically used to: obtain an image stream listener manager instance through the network image resource class; generate an image stream listener that matches the image stream listener manager instance; and obtain image decoding data corresponding to the target image based on the image stream listener.
[0103] In one embodiment, the first data acquisition module 906 is further configured to: execute an image listening event corresponding to the target image based on the image stream listener; when the image listening event is called back, obtain an image information instance generated by decoding the target image based on the callback result; and obtain the image decoding data corresponding to the target image based on the image information instance.
[0104] In one embodiment, the first data acquisition module 906 is further configured to: when the image decoding data type matching the image information instance is a byte data type, acquire the image decoding data of the byte data type corresponding to the target image; based on the decoding data conversion relationship matching the image information instance, convert the image decoding data of the byte data type into image decoding data of the integer list type; and use the image decoding data of the integer list type as the image decoding data corresponding to the target image.
[0105] In one embodiment, the second data acquisition module 908 is specifically used to: obtain image decoding data of the integer list type through a byte synchronous reading method. The image loading module 910 is specifically used to: convert the image decoding data of the integer list type into an image object through pixel decoding; and, based on the image object, perform rendering and loading processing on the target image through the original image rendering component.
[0106] Each module in the aforementioned image loading device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0107] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements an image loading method. The display unit of the computer device is used to form a visually visible image. It can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0108] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0109] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0110] Get the image loading request;
[0111] Find the image decoding data corresponding to the image loading request locally;
[0112] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the decoded image data is cached.
[0113] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0114] The target image is rendered and loaded based on the image decoding data.
[0115] In one embodiment, when the processor executes the computer program, it further implements the following steps: based on the preset image provider class, it obtains the image decoding data corresponding to the target image through the image stream listener manager, and caches the image decoding data obtained by decoding.
[0116] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining an image stream listener instance through a local image resource class; generating an image stream listener that matches the image stream listener instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0117] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining an image stream listener instance through a network image resource class; generating an image stream listener that matches the image stream listener instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0118] In one embodiment, when the processor executes the computer program, it further performs the following steps: executing an image listening event corresponding to the target image based on the image stream listener; when the image listening event is called back, obtaining an image information instance generated by decoding the target image based on the callback result; and obtaining the image decoding data corresponding to the target image based on the image information instance.
[0119] In one embodiment, when the processor executes the computer program, it further implements the following steps: when the image decoding data type matching the image information instance is a byte data type, it obtains the image decoding data of the byte data type corresponding to the target image; based on the decoding data conversion relationship matching the image information instance, it converts the image decoding data of the byte data type into image decoding data of the integer list type; and it uses the image decoding data of the integer list type as the image decoding data corresponding to the target image.
[0120] In one embodiment, when the processor executes the computer program, it further performs the following steps: obtaining image decoding data of type integer list through a byte synchronous reading method; converting the image decoding data of type integer list into an image object through pixel decoding; and rendering and loading the target image based on the image object through a raw image rendering component.
[0121] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:
[0122] Get the image loading request;
[0123] Find the image decoding data corresponding to the image loading request locally;
[0124] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the decoded image data is cached.
[0125] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0126] The target image is rendered and loaded based on the image decoding data.
[0127] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: based on the preset image provider class, it obtains the image decoding data corresponding to the target image through the image stream listener manager, and caches the image decoding data obtained by decoding.
[0128] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining an image stream listener instance through a local image resource class; generating an image stream listener that matches the image stream listener instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0129] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining an image stream listener instance through a network image resource class; generating an image stream listener that matches the image stream listener instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0130] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: executing an image listening event corresponding to the target image based on the image stream listener; when the image listening event is called back, obtaining an image information instance generated by decoding the target image based on the callback result; and obtaining the image decoding data corresponding to the target image based on the image information instance.
[0131] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: when the image decoding data type matching the image information instance is a byte data type, obtain the image decoding data of the byte data type corresponding to the target image; based on the decoding data conversion relationship matching the image information instance, convert the image decoding data of the byte data type into image decoding data of the integer list type; and use the image decoding data of the integer list type as the image decoding data corresponding to the target image.
[0132] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining image decoding data of type integer list through a byte synchronous reading method; converting the image decoding data of type integer list into an image object through pixel decoding; and rendering and loading the target image based on the image object through the original image rendering component.
[0133] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, performs the following steps:
[0134] Get the image loading request;
[0135] Find the image decoding data corresponding to the image loading request locally;
[0136] When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the decoded image data is cached.
[0137] When the image decoding data corresponding to the image loading request is found, the image decoding data is obtained from the local cache data;
[0138] The target image is rendered and loaded based on the image decoding data.
[0139] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: based on the preset image provider class, it obtains the image decoding data corresponding to the target image through the image stream listener manager, and caches the image decoding data obtained by decoding.
[0140] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining an image stream listener instance through a local image resource class; generating an image stream listener that matches the image stream listener instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0141] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining an image stream listener instance through a network image resource class; generating an image stream listener that matches the image stream listener instance; and obtaining image decoding data corresponding to the target image based on the image stream listener.
[0142] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: executing an image listening event corresponding to the target image based on the image stream listener; when the image listening event is called back, obtaining an image information instance generated by decoding the target image based on the callback result; and obtaining the image decoding data corresponding to the target image based on the image information instance.
[0143] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: when the image decoding data type matching the image information instance is a byte data type, obtain the image decoding data of the byte data type corresponding to the target image; based on the decoding data conversion relationship matching the image information instance, convert the image decoding data of the byte data type into image decoding data of the integer list type; and use the image decoding data of the integer list type as the image decoding data corresponding to the target image.
[0144] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: obtaining image decoding data of type integer list through a byte synchronous reading method; converting the image decoding data of type integer list into an image object through pixel decoding; and rendering and loading the target image based on the image object through the original image rendering component.
[0145] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0146] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0147] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0148] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. An image loading method, characterized in that, The method includes: Get the image loading request; The image decoding data corresponding to the image loading request is located locally, and the image decoding data is the pixel data obtained after decoding. When no image decoding data corresponding to the image loading request is found, the target image indicated by the image loading request is decoded, and the decoded image decoding data is cached. The image decoding data corresponding to the target image includes image decoding data of integer list type. The image decoding data of integer list type is obtained by converting the image decoding data of byte data type corresponding to the target image, so that the image decoding data of integer list type can be saved to the local disk through the corresponding interface. When the image decoding data corresponding to the image loading request is found, the image decoding data of the integer list type is read from the local cache data through byte synchronization; The image decoding data, which is a list of integers, is converted into an image object through pixel decoding; based on the image object, the target image is rendered and loaded using the original image rendering component.
2. The method according to claim 1, characterized in that, The decoding of the target image corresponding to the image loading request, and the cached image decoding data obtained includes: Based on the image loading request, locate the image component and obtain the preset image provider class in the image component; Based on the preset image provider class, the image decoding data corresponding to the target image is obtained through the image stream listener manager, and the decoded image data is cached.
3. The method according to claim 2, characterized in that, The preset image provider class inherits from the local image resource class. The step of obtaining the image decoding data corresponding to the target image through the image stream listener manager based on the preset image provider class includes: Obtain an instance of the image stream listener manager through the local image resource class; Generate an image stream listener that matches the image stream listener manager instance; The image stream listener acquires the image decoding data corresponding to the target image.
4. The method according to claim 2, characterized in that, The preset image provider class inherits from the network image resource class. The step of obtaining the image decoding data corresponding to the target image through the image stream listener manager based on the preset image provider class includes: Obtain an instance of the image stream listener manager through the aforementioned network image resource class; Generate an image stream listener that matches the image stream listener manager instance; The image stream listener acquires the image decoding data corresponding to the target image.
5. The method according to claim 3, characterized in that, The step of obtaining the image decoding data corresponding to the target image based on the image stream listener includes: The image stream listener executes the image listening event corresponding to the target image; When the image listening event is called back, the image information instance generated by decoding the target image is obtained based on the callback result; Based on the image information instance, obtain the image decoding data corresponding to the target image.
6. The method according to claim 5, characterized in that, The step of obtaining the image decoding data corresponding to the target image based on the image information instance includes: When the image decoding data type that matches the image information instance is a byte data type, obtain the image decoding data of the byte data type corresponding to the target image; Based on the decoding data conversion relationship that matches the image information instance, the image decoding data of the byte data type is converted into image decoding data of the integer list type; The image decoding data of the integer list type is used as the image decoding data corresponding to the target image.
7. An image loading device, characterized in that, The device includes: The request retrieval module is used to retrieve image loading requests. The decoding data lookup module is used to look up the image decoding data corresponding to the image loading request locally. The image decoding data is the pixel data obtained after decoding. The first data acquisition module is used to decode the target image indicated by the image loading request when no image decoding data corresponding to the image loading request is found, and to cache the image decoding data obtained by decoding. The image decoding data corresponding to the target image includes image decoding data of integer list type. The image decoding data of integer list type is obtained by converting the image decoding data of byte data type corresponding to the target image, so as to save the image decoding data of integer list type to the local disk through the corresponding interface. The second data acquisition module is used to read the image decoding data of the integer list type from the local cache data through byte synchronization when the image decoding data corresponding to the image loading request is found. The image loading module is used to convert the image decoding data of the integer list type into an image object through pixel decoding; based on the image object, the target image is rendered and loaded through the original image rendering component.
8. The apparatus according to claim 7, characterized in that, The first data acquisition module is specifically used for: finding an image component based on the image loading request, obtaining a preset image provider class in the image component; obtaining image decoding data corresponding to the target image through an image stream listener manager based on the preset image provider class, and caching the image decoding data obtained by decoding.
9. The apparatus according to claim 8, characterized in that, The preset image provider class inherits from the local image resource class. The first data acquisition module is specifically used to: obtain an image stream listener manager instance through the local image resource class; generate an image stream listener that matches the image stream listener manager instance; and obtain image decoding data corresponding to the target image based on the image stream listener.
10. The apparatus according to claim 8, characterized in that, The preset image provider class inherits from the network image resource class. The first data acquisition module is specifically used to: obtain an image stream listener manager instance through the network image resource class; generate an image stream listener that matches the image stream listener manager instance; and obtain image decoding data corresponding to the target image based on the image stream listener.
11. The apparatus according to claim 9, characterized in that, The first data acquisition module is further configured to: execute an image listening event corresponding to the target image based on the image stream listener; when the image listening event is called back, obtain an image information instance generated by decoding the target image based on the callback result; Based on the image information instance, obtain the image decoding data corresponding to the target image.
12. The apparatus according to claim 11, characterized in that, The first data acquisition module is further configured to: when the image decoding data type matching the image information instance is a byte data type, acquire the image decoding data of the byte data type corresponding to the target image; based on the decoding data conversion relationship matching the image information instance, convert the image decoding data of the byte data type into image decoding data of the integer list type; and use the image decoding data of the integer list type as the image decoding data corresponding to the target image.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Network image display method, device and user terminal
CN106941567A
Webpage display method and device
CN108073647A
Picture loading method and device
CN110555118A
Image loading method and device, computer equipment and storage medium
CN111583347A