Picture loading method and system based on network speed
Patent Information
- Application Number
- CN202411386154.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-24
AI Technical Summary
Traditional image loading methods In complex and changeable network environments, fixed image resolution leads to excessive loading time and excessive data traffic consumption when the network is in poor condition, and may not meet the user's high quality when the network is in good condition. The need for visual effects.
By constructing a database that contains low -resolution, medium resolution and high resolution pictures, and selects the appropriate picture according to the client's network speed. Specific steps include receiving network requests, adding the current network speed parameters, obtaining the value of the network speed parameter, and returning the corresponding resolution picture from the database according to this value.
It achieves a balance between image quality and loading speed. When the network condition is poor, low-resolution images are loaded to reduce loading time and data traffic consumption. When the network condition is good, high-resolution images are loaded to provide high-quality visual effects. When the situation is normal, load medium-resolution images to avoid image quality that is too low or too high, affecting the user experience.
Smart Images

Figure CN119363726A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and system for loading an image based on network speed. Background Art
[0002] With the rapid development of the Internet, image loading in network applications has become an increasingly important performance optimization point. In today's complex and ever-changing network environment, users' network conditions may vary significantly due to factors such as geographic location, network service provider, and device performance. Traditional image loading methods often use a fixed image resolution. This one-size-fits-all approach will result in long loading times and excessive data traffic consumption when network conditions are poor, seriously affecting user experience; while when network conditions are good, the loaded image resolution may be too low to meet users' demand for high-quality visual effects. Summary of the invention
[0003] In view of the above-mentioned defects, the present invention proposes a network speed-based image loading method and system, aiming to solve the problem that in today's complex and changeable network environment, the traditional image loading method often adopts a fixed image resolution, which will lead to a long loading time and excessive data traffic consumption when the network condition is poor. When the network condition is good, the loaded image resolution may be too low to meet the user's demand for high-quality visual effects.
[0004] To achieve this object, the present invention adopts the following technical solutions:
[0005] A method for loading an image based on network speed includes the following steps:
[0006] Step S1: constructing an image database, the image database including low-resolution images, medium-resolution images and high-resolution images;
[0007] Step S2: receiving a network request and adding a current network speed parameter to the network request;
[0008] Step S3: Obtain the value of the current network speed parameter in the network request;
[0009] Step S4: according to the value of the current network speed parameter, return the corresponding resolution image from the image database;
[0010] If the value of the current network speed parameter is greater than 0 and less than the first preset value, a low-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the first preset value and less than the second preset value, a medium-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the second preset value, a high-resolution image is returned from the image database.
[0011] Preferably, step S3 specifically includes the following sub-steps:
[0012] Step S31: calling the getSystemService method to obtain the ConnectivityManager object to obtain the connection service of the current network;
[0013] Step S32: calling the getActiveNetworkInfo method to obtain the connection information of the current network;
[0014] Step S33: calling the getNetworkCapabilities method to obtain the capability information of the current network;
[0015] Step S34: call the getLinkDownstreamBandwidthKbps method to obtain the bandwidth speed of the current downstream network, and call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
[0016] Preferably, the method further includes the following steps: regularly updating the pictures in the picture database.
[0017] Another aspect of the present application provides a network speed-based image loading system, the system comprising:
[0018] A construction module is used to construct an image database, where the image database includes low-resolution images, medium-resolution images, and high-resolution images;
[0019] A receiving module, used for receiving network requests;
[0020] Add a module to add the current network speed parameter in the network request;
[0021] The acquisition module is used to obtain the value of the current network speed parameter in the network request;
[0022] The return module is used to return the corresponding resolution image from the image database according to the value of the current network speed parameter; if the value of the current network speed parameter is greater than 0 and less than a first preset value, a low-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the first preset value and less than a second preset value, a medium-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the second preset value, a high-resolution image is returned from the image database.
[0023] Preferably, the acquisition module includes:
[0024] The first acquisition submodule is used to call the getSystemService method to obtain the ConnectivityManager object to obtain the connection service of the current network;
[0025] The second acquisition submodule is used to call the getActiveNetworkInfo method to obtain the connection information of the current network;
[0026] The third acquisition submodule is used to call the getNetworkCapabilities method to obtain the capability information of the current network;
[0027] The fourth acquisition submodule is used to call the getLinkDownstreamBandwidthKbps method to obtain the bandwidth speed of the current network downstream;
[0028] The fifth acquisition submodule is used to call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
[0029] Preferably, the updating module is used to regularly update the pictures in the picture database.
[0030] The technical solution provided by the embodiments of the present application may have the following beneficial effects:
[0031] In this solution, a database containing pictures of different resolutions is constructed, and appropriate pictures are selected for loading according to the client's network speed, so as to achieve a balance between picture quality and loading speed. When the network condition is poor, low-resolution pictures are loaded to reduce loading time and data traffic consumption. When the network condition is good, high-resolution pictures are loaded to provide high-quality visual effects. When the network condition is normal, medium-resolution pictures are loaded to avoid low or high picture quality, which affects the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 It is a flowchart of the steps of the image loading method based on network speed. DETAILED DESCRIPTION
[0033] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0034] A method for loading an image based on network speed includes the following steps:
[0035] Step S1: constructing an image database, the image database including low-resolution images, medium-resolution images and high-resolution images;
[0036] Step S2: receiving a network request and adding a current network speed parameter to the network request;
[0037] Step S3: Obtain the value of the current network speed parameter in the network request;
[0038] Step S4: according to the value of the current network speed parameter, return the corresponding resolution image from the image database;
[0039] If the value of the current network speed parameter is greater than 0 and less than the first preset value, a low-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the first preset value and less than the second preset value, a medium-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the second preset value, a high-resolution image is returned from the image database.
[0040] This solution is a method of loading pictures based on network speed, such as Figure 1As shown, the first step is to build a picture database, which includes low-resolution pictures, medium-resolution pictures and high-resolution pictures. Specifically, by building a picture database, it is beneficial to store and manage pictures of different resolutions. The second step is to receive a network request and add the current network speed parameter in the network request. Specifically, the network speed is added as a parameter to the network request so that the server can know the network status of the client and make a more reasonable response. The third step is to obtain the value of the current network speed parameter in the network request. Specifically, by obtaining the value of the current network speed parameter in the network request, it is beneficial to decide which resolution picture to return based on it later. The fourth step is to return the corresponding resolution picture from the picture database according to the value of the current network speed parameter; if the value of the current network speed parameter is greater than 0 and less than the first preset value, the low-resolution picture is returned from the picture database; if the value of the current network speed parameter is greater than the first preset value and less than the second preset value, the medium-resolution picture is returned from the picture database; if the value of the current network speed parameter is greater than the second preset value, the high-resolution picture is returned from the picture database. Specifically, the server selects a picture of appropriate resolution according to the network speed of the client to return, which can effectively balance the relationship between picture quality and loading speed. In this embodiment, the first preset value is 100, and the second preset value is 500. If the value of the current network speed parameter is greater than 0 and less than 100, it means that the network status of the client is poor at this time, so low-resolution images are loaded; if the value of the current network speed parameter is greater than 100 and less than 500, it means that the network status of the client is normal at this time, so medium-resolution images are loaded; if the value of the current network speed parameter is greater than 500, it means that the network status of the client is good at this time, so high-resolution images are loaded. For example, when the Android application client requests the news details page interface, the news details page interface will receive the request and add the current network speed parameter to the request. At this time, the request is https: / / newsapi / detial?id=xxx&&speed=300. Since the value of the current network speed parameter is 300, and 300 is between 100 and 500, a medium-resolution image is returned.
[0041] In this solution, a database containing pictures of different resolutions is constructed, and appropriate pictures are selected for loading according to the client's network speed, so as to achieve a balance between picture quality and loading speed. When the network condition is poor, low-resolution pictures are loaded to reduce loading time and data traffic consumption. When the network condition is good, high-resolution pictures are loaded to provide high-quality visual effects. When the network condition is normal, medium-resolution pictures are loaded to avoid low or high picture quality, which affects the user experience.
[0042] Preferably, in step S3, the following sub-steps are specifically included:
[0043] Step S31: calling the getSystemService method to obtain the ConnectivityManager object to obtain the connection service of the current network;
[0044] Step S32: calling the getActiveNetworkInfo method to obtain the connection information of the current network;
[0045] Step S33: calling the getNetworkCapabilities method to obtain the capability information of the current network;
[0046] Step S34: call the getLinkDownstreamBandwidthKbps method to obtain the bandwidth speed of the current downstream network, and call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
[0047] In this embodiment, in step S31, ConnectivityManager is an important class in the Android system for managing network connection status and network information. The getSystemService method is an important method of the Context class in the Android framework. By calling the getSystemService method of Context and passing in Context.CONNECTIVITY_SERVICE as a parameter, the ConnectivityManager object is obtained, which represents the connection service of the network. In step S32, the getActiveNetworkInfo method is a method of the ConnectivityManager class in the Android system, which is used to obtain the network connection information of the device's current activity. Therefore, the getActiveNetworkInfo method can be called to obtain the connection information of the current network. In step S33, the getNetworkCapabilities method is a method of the ConnectivityManager class in the Android system, which is used to obtain the capability information of the specified network. Therefore, the getNetworkCapabilities method can be called to obtain the capability information of the current network. In step S34, the getLinkDownstreamBandwidthKbps method is a method of the ConnectivityManager class in the Android system, which is used to obtain the downlink bandwidth of the network connection. Therefore, the getLinkDownstreamBandwidthKbps method can be called to obtain the bandwidth speed of the current network downstream. The getLinkUpstreamBandwidthKbps method is a method of the ConnectivityManager class in the Android system, which is used to obtain the upstream bandwidth of the network connection. Therefore, you can call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
[0048] Preferably, the following step is further included: regularly updating the pictures in the picture database. In this embodiment, updating the pictures in the picture database specifically includes checking and replacing outdated, damaged or no longer needed pictures, and adding new, higher quality pictures to the picture database. Regularly updating the picture database can ensure that the picture database is kept up to date, reflecting the latest content changes and image quality improvements, thereby improving user experience and meeting the latest needs of users.
[0049] Another aspect of the present application provides a network speed-based image loading system, the system comprising:
[0050] A construction module is used to construct an image database, where the image database includes low-resolution images, medium-resolution images, and high-resolution images;
[0051] A receiving module, used for receiving network requests;
[0052] Add a module to add the current network speed parameter in the network request;
[0053] The acquisition module is used to obtain the value of the current network speed parameter in the network request;
[0054] The return module is used to return the corresponding resolution image from the image database according to the value of the current network speed parameter; if the value of the current network speed parameter is greater than 0 and less than a first preset value, a low-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the first preset value and less than a second preset value, a medium-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the second preset value, a high-resolution image is returned from the image database.
[0055] The scheme is a picture loading system based on network speed, which achieves a balance between picture quality and loading speed through the cooperation of building modules, receiving modules, adding modules, obtaining modules and returning modules. When the network condition is poor, low-resolution pictures are loaded to reduce loading time and data traffic consumption. When the network condition is good, high-resolution pictures are loaded to provide high-quality visual effects. When the network condition is normal, medium-resolution pictures are loaded to avoid low or high picture quality, which affects the user experience.
[0056] Preferably, the acquisition module includes:
[0057] The first acquisition submodule is used to call the getSystemService method to obtain the ConnectivityManager object to obtain the connection service of the current network;
[0058] The second acquisition submodule is used to call the getActiveNetworkInfo method to obtain the connection information of the current network;
[0059] The third acquisition submodule is used to call the getNetworkCapabilities method to obtain the capability information of the current network;
[0060] The fourth acquisition submodule is used to call the getLinkDownstreamBandwidthKbps method to obtain the bandwidth speed of the current network downstream;
[0061] The fifth acquisition submodule is used to call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
[0062] In this embodiment, the current network speed in the network request is obtained through the cooperation of the first acquisition submodule, the second acquisition submodule, the third acquisition submodule, the fourth acquisition submodule and the fifth acquisition submodule.
[0063] Preferably, the update module is used to regularly update the pictures in the picture database. In this embodiment, by setting the update module, it is possible to ensure that the picture database is kept up to date, reflecting the latest content changes and image quality improvements, thereby improving user experience and meeting the latest needs of users.
[0064] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0065] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A method for loading pictures based on network speed, characterized in that: The following steps are involved: Step S1: constructing an image database, the image database including low-resolution images, medium-resolution images and high-resolution images; Step S2: receiving a network request and adding a current network speed parameter to the network request; Step S3: Obtain the value of the current network speed parameter in the network request; Step S4: according to the value of the current network speed parameter, return the corresponding resolution image from the image database; If the value of the current network speed parameter is greater than 0 and less than the first preset value, a low-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the first preset value and less than the second preset value, a medium-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the second preset value, a high-resolution image is returned from the image database.
2. The method for loading pictures based on network speed according to claim 1, characterized in that: In step S3, the following sub-steps are specifically included: Step S31: calling the getSystemService method to obtain the ConnectivityManager object to obtain the connection service of the current network; Step S32: calling the getActiveNetworkInfo method to obtain the connection information of the current network; Step S33: calling the getNetworkCapabilities method to obtain the capability information of the current network; Step S34: call the getLinkDownstreamBandwidthKbps method to obtain the bandwidth speed of the current downstream network, and call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
3. The method for loading pictures based on network speed according to claim 1, characterized in that: The following steps are also included: Update the pictures in the picture database regularly.
4. A network speed-based image loading system, using the network speed-based image loading method according to any one of claims 1 to 3, characterized in that: The system comprises: A construction module is used to construct an image database, where the image database includes low-resolution images, medium-resolution images, and high-resolution images; A receiving module, used for receiving network requests; Add a module to add the current network speed parameter in the network request; The acquisition module is used to obtain the value of the current network speed parameter in the network request; The return module is used to return the corresponding resolution image from the image database according to the value of the current network speed parameter; if the value of the current network speed parameter is greater than 0 and less than a first preset value, a low-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the first preset value and less than a second preset value, a medium-resolution image is returned from the image database; if the value of the current network speed parameter is greater than the second preset value, a high-resolution image is returned from the image database.
5. The image loading system based on network speed according to claim 4, characterized in that: The acquisition module comprises: The first acquisition submodule is used to call the getSystemService method to obtain the ConnectivityManager object to obtain the connection service of the current network; The second acquisition submodule is used to call the getActiveNetworkInfo method to obtain the connection information of the current network; The third acquisition submodule is used to call the getNetworkCapabilities method to obtain the capability information of the current network; The fourth acquisition submodule is used to call the getLinkDownstreamBandwidthKbps method to obtain the bandwidth speed of the current network downstream; The fifth acquisition submodule is used to call the getLinkUpstreamBandwidthKbps method to obtain the bandwidth speed of the current upstream network.
6. The image loading system based on network speed according to claim 4, characterized in that: Also includes: The updating module is used to regularly update the images in the image database.