Picture processing method and related device
The image processing method addresses excessive memory usage by compressing images based on screen pixel density and control size, ensuring efficient memory management across devices.
Patent Information
- Application Number
- CN202411221263.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-02
- Publication Date
- 2024-12-27
AI Technical Summary
The increasing number of images in applications leads to excessive memory usage, causing page freezes and application closures due to insufficient memory.
An image processing method that determines the pixel size based on screen pixel density and control size, compresses images if they exceed the pixel size, and loads the compressed images, reducing memory usage.
Adapts to different devices and scenarios, reducing memory usage by replacing large images with compressed ones, thus preventing freezes and closures.
Smart Images

Figure CN119200931A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to an image processing method and related devices. Background Art
[0002] An application is a computer program used to perform certain functions, which can usually be run on terminal devices (such as mobile phones, computers, etc.) for user use.
[0003] As a medium for recording memories or displaying information, pictures are a common interactive element in the use of applications. For example, in communication applications, users can transmit communication information by sending pictures to each other. In social applications, users can share information by posting pictures. Accordingly, loading and storing pictures is one of the important and indispensable functions in applications. However, as the number of pictures increases, the memory usage is also increasing. In serious cases, it may cause page freezes during the use of the application, and even force the application to close due to insufficient memory.
[0004] It can be seen that how to process images to avoid excessive memory usage is of great significance. Summary of the invention
[0005] In order to solve the above technical problems, the present application provides an image processing method and related devices, which are conducive to reducing memory usage.
[0006] The embodiments of the present application disclose the following technical solutions:
[0007] On the one hand, an embodiment of the present application provides a method for processing an image, the method comprising:
[0008] Obtaining a screen pixel density corresponding to a target device for running a target application, and obtaining a control size corresponding to an image loading control in the target application, wherein the image loading control is used to load a target image;
[0009] Determine the pixel size corresponding to the image loading control according to the screen pixel density and the control size;
[0010] If the image pixel size of the target image exceeds the pixel size, compressing the target image based on the pixel size to obtain a compressed image, wherein the image pixel size of the compressed image meets the pixel size;
[0011] When the target application is running on the target device, the compressed image is loaded through the image loading control.
[0012] On the other hand, an embodiment of the present application provides a picture processing device, the device comprising an acquisition unit, a determination unit, a compression unit and a loading unit:
[0013] The acquisition unit is used to acquire the screen pixel density corresponding to the target device for running the target application, and to acquire the control size corresponding to the picture loading control in the target application, wherein the picture loading control is used to load the target picture;
[0014] The determining unit is used to determine the pixel size corresponding to the image loading control according to the screen pixel density and the control size;
[0015] The compression unit is configured to compress the target image based on the pixel size to obtain a compressed image if the image pixel size of the target image exceeds the pixel size, and the image pixel size of the compressed image meets the pixel size;
[0016] The loading unit is used to load the compressed image through the image loading control when the target application is running on the target device.
[0017] In another aspect, an embodiment of the present application provides a computer device, the computer device comprising a processor and a memory:
[0018] The memory is used to store program code and transmit the program code to the processor;
[0019] The processor is used to execute the image processing method described in the above aspects according to the instructions in the program code.
[0020] It can be seen from the above technical solution that first, the screen pixel density corresponding to the target device for running the target application is obtained, and the control size corresponding to the picture loading control in the target application is obtained, and the picture loading control is used to load the target picture. Then, the pixel size corresponding to the picture loading control can be determined according to the screen pixel density and the control size. Among them, the screen pixel density can reflect the screen display performance of the target device, and specifically can reflect the number of pixels that can be displayed in an area of a unit size in the screen of the target device. And the control size can reflect the size of the area used to load the target picture, so the pixel size determined based on the two can reflect the number of pixels that can be displayed in the area identified by the picture loading control. Then, if the pixel size of the target picture exceeds the pixel size corresponding to the picture loading control, it indicates that the target picture at this time is too large, and the entire target picture cannot be fully loaded through the picture loading control. At this time, the target picture can be compressed based on the pixel size to obtain a compressed picture, and the pixel size of the compressed picture meets the pixel size. Finally, when the target application runs on the target device, the compressed picture can be loaded through the picture loading control. Based on this, when the image loading control cannot completely load the entire target image, the target image is replaced by a compressed image that meets the pixel size through compression processing. Since the pixel size of the compressed image is smaller than the pixel size of the target image, it is helpful to reduce memory usage. And the pixel size of the image loading control is determined based on the control size and the screen pixel density, so this application can be adapted to different image loading controls and image loading requirements on different devices, with higher versatility, and can be flexibly adapted to different image loading scenarios to reduce memory usage. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are 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 work.
[0022] Figure 1 A flowchart of a method for processing an image provided by an embodiment of the present application;
[0023] Figure 2 A schematic diagram of a picture loading set provided in an embodiment of the present application;
[0024] Figure 3 A schematic diagram of a target page provided in an embodiment of the present application;
[0025] Figure 4 A schematic diagram of a calculation result of a least-used rule for an image provided in an embodiment of the present application;
[0026] Figure 5 A structural diagram of an image processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] 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.
[0028] The image processing method provided in the embodiment of the present application can be implemented by a computer device, which can be a terminal device or a server, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. Terminal devices include but are not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, etc. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and this application does not impose any restrictions on this.
[0029] The specific examples are as follows:
[0030] Figure 1 This is a flowchart of a method for processing an image provided in an embodiment of the present application, which is described by taking a terminal device as the aforementioned computer device as an example. The method includes S101-S104:
[0031] S101: Obtaining a screen pixel density corresponding to a target device for running a target application, and obtaining a control size corresponding to an image loading control in the target application.
[0032] Among them, the image loading control is used to load the target image. The screen pixel density can reflect the screen display performance of the target device, and specifically can reflect the number of pixels that can be displayed in a unit size area on the screen of the target device. In practical applications, the screen pixel density can be recorded as Density, which specifically reflects the number of pixels within 1 inch on the screen of the target device. Usually, the screen display performance of different devices varies, so the corresponding screen pixel density is different.
[0033] And, the control size can reflect the size of the area used to load the target image. Usually, different applications have different corresponding image loading controls, and their corresponding control sizes will also be different. In actual applications, the image loading control can be recorded as a View control, and the control size of the image loading control can be determined based on the width and height of the View control given in the user interface (UI) design draft of the application.
[0034] S102: Determine the pixel size corresponding to the image loading control according to the screen pixel density and the control size.
[0035] Since the screen pixel density can reflect the number of pixels that can be displayed in a unit-sized area on the target device's screen, and the control size can reflect the size of the area used to load the target image, the pixel size determined based on the two can reflect the number of pixels that can be displayed in the area identified by the image loading control, that is, the pixel size corresponding to the image loading control.
[0036] In actual applications, when the program starts, a picture pixel size tool class ChannelImageConst can be provided to calculate the actual required width and height pixel values corresponding to different picture loading controls based on the screen pixel density and the width and height of the View control given in the UI design draft.
[0037] S103: If the pixel size of the target image exceeds the pixel size, compress the target image based on the pixel size to obtain a compressed image.
[0038] If the pixel size of the target image exceeds the aforementioned pixel size, it means that the target image is too large and the image loading control cannot load the entire target image completely. Therefore, loading based on the original image will cause unnecessary memory usage. In this regard, when the pixel size of the target image exceeds the aforementioned pixel size, the target image can be compressed based on the pixel size to obtain a compressed image, and the pixel size of the compressed image meets the pixel size.
[0039] Based on this, when the image loading control cannot completely load the entire target image, the target image is replaced by a compressed image that meets the pixel size through compression processing. Since the pixel size of the compressed image is smaller than the pixel size of the target image, it is helpful to reduce memory usage.
[0040] Correspondingly, if the pixel size of the target image does not exceed the aforementioned pixel size, it indicates that the original image size of the target image at this time does not exceed the pixel size of the image loading control. Therefore, loading based on the original image will not cause unnecessary memory usage, so no processing is required at this time. However, because this application calculates the pixel size of the image loading control, it is possible to accurately identify which images need to be compressed and which images do not need to be compressed, thereby avoiding unnecessary image compression on the basis of reducing memory usage and saving compression resources.
[0041] S104: When the target application is running on the target device, the compressed image is loaded through the image loading control.
[0042] Finally, when the target application runs on the target device, the compressed image can be loaded through the image loading control. Based on this, it can adapt to different image loading controls and image loading requirements on different devices, has higher versatility, can be flexibly adapted to different image loading scenarios, and reduces memory usage.
[0043] It should be noted that this application does not make any limitation on how to compress or how to load compressed images. For ease of understanding, this application embodiment provides the following methods as examples:
[0044] In a possible implementation, the pixel size can be spliced into the image address corresponding to the target image to obtain a splicing address. Based on this, the splicing address can indicate the required pixel size. Correspondingly, if the image pixel size of the target image exceeds the pixel size, the target image can be directly compressed based on the pixel size carried in the splicing address to obtain a compressed image.
[0045] Accordingly, in a possible implementation, when the aforementioned S104 is specifically implemented, when the target application is running on the target device, the compressed image can be loaded based on the image address corresponding to the compressed image through the image loading control.
[0046] In actual applications, image loading can be implemented based on the third-party image loading framework Fresco. Usually, the aforementioned image addresses are mostly constructed based on Uniform Resource Locator (URL). In order to adapt to this image loading framework, the subsequent splicing address can be constructed based on Uniform Resource Identifier (URI) in addition to carrying pixel size.
[0047] It can be seen from the above technical solution that first, the screen pixel density corresponding to the target device for running the target application is obtained, and the control size corresponding to the picture loading control in the target application is obtained, and the picture loading control is used to load the target picture. Then, the pixel size corresponding to the picture loading control can be determined according to the screen pixel density and the control size. Among them, the screen pixel density can reflect the screen display performance of the target device, and specifically can reflect the number of pixels that can be displayed in an area of a unit size in the screen of the target device. And the control size can reflect the size of the area used to load the target picture, so the pixel size determined based on the two can reflect the number of pixels that can be displayed in the area identified by the picture loading control. Then, if the pixel size of the target picture exceeds the pixel size corresponding to the picture loading control, it indicates that the target picture at this time is too large, and the entire target picture cannot be fully loaded through the picture loading control. At this time, the target picture can be compressed based on the pixel size to obtain a compressed picture, and the pixel size of the compressed picture meets the pixel size. Finally, when the target application runs on the target device, the compressed picture can be loaded through the picture loading control. Based on this, when the image loading control cannot completely load the entire target image, the target image is replaced by a compressed image that meets the pixel size through compression processing. Since the pixel size of the compressed image is smaller than the pixel size of the target image, it is helpful to reduce memory usage. And the pixel size of the image loading control is determined based on the control size and the screen pixel density, so this application can be adapted to different image loading controls and image loading requirements on different devices, with higher versatility, and can be flexibly adapted to different image loading scenarios to reduce memory usage.
[0048] In addition, in order to release memory in time, the present application embodiment also provides the following example of an implementation method for cleaning up pictures:
[0049] In a possible implementation, when loading a compressed image, a key value entry corresponding to the compressed image is stored in the image loading set corresponding to the target application. The key value entry may include the image address of the compressed image and the number of times the compressed image is loaded. Specifically, the number of times the compressed image is loaded may be used to indicate the number of times the compressed image is displayed through the image loading control in the page of the target application. Next, in response to the sliding operation implemented by the target application satisfying the image cleaning condition, it is indicated that the images in the cache may be cleaned. Specifically, the images stored in the image loading set may be cleaned based on the number of times the images stored in the image loading set are loaded.
[0050] Based on this, the loading status of the images is recorded by storing key-value entries. In this way, when cleaning is needed, it is more convenient to clean up the images in combination with the loading status.
[0051] In order to better store and manage the loading status of pictures, in a possible implementation, the corresponding picture loading list array can be configured in the picture loading collection according to the page. In specific implementation, if the target page of the target application includes a picture loading control, the picture loading collection includes the picture loading list array corresponding to each page in the target application, and different pages correspond to different picture loading list arrays, that is, one page corresponds to one picture loading list array.
[0052] Accordingly, the aforementioned storing the key value entries corresponding to the target image in the image loading set corresponding to the target application when loading the compressed image may include: storing the key value entries corresponding to the target image in the image loading list array corresponding to the target page when loading the compressed image. Based on this, the key value entries of each image are stored in the image loading list array corresponding to the page that loads the image. In this way, it is possible to realize the storage of image loading conditions distinguished from pages and in units of pages.
[0053] And, the aforementioned response to the sliding operation implemented through the target application meeting the picture cleaning condition, based on the number of times the pictures stored in the picture loading set are loaded, the pictures stored in the picture loading set are cleaned up, which may include: in response to the sliding operation implemented through the target page meeting the picture cleaning condition, based on the number of times the pictures stored in the picture loading list array corresponding to the target page are loaded, the pictures stored in the picture loading list array corresponding to the target page are cleaned up. In this way, when cleaning up, the picture loading list array of the page to which the picture belongs is also cleaned up, and the picture loading list arrays of each page are decoupled to reduce interference and achieve better picture management.
[0054] In practical applications, the image loading collection can be recorded as a Map collection. For the convenience of storage, the loading status of each image can be stored based on a key-value pair (Key-Value) storage method. For ease of understanding, the present application embodiment also provides the following Figure 2 The diagram of a picture loading collection shown in the figure, specifically, in the Map collection, different pages can be distinguished, and keys corresponding to each page can be created, that is, each page can correspond to a key, and then each key can correspond to a List array, so as to better store and manage the picture loading status of each page. Correspondingly, the key value entry of the picture can be used as the Value. Usually, the key value entry can be recorded as the Entry object of the compressed picture, which can specifically include the address uri of the compressed picture and the number of loads count.
[0055] It should be noted that the present application does not impose any limitation on how to determine the image cleaning conditions. For ease of understanding, the present application provides the following methods as examples:
[0056] In actual applications, the user can perform a sliding operation on the target page through the target device to switch the pictures displayed on the device screen. Figure 3 A schematic diagram of a target page is shown, specifically:
[0057] exist Figure 3 In the example, taking the aforementioned target device as a mobile phone, the mobile phone screen is the display area of the device, and the portion of the target application displayed on the mobile phone screen can be considered as the aforementioned target page. And, Figure 3 Each item in the example can be considered as a picture loading control (ViewHolder) that carries pictures. It can be understood that as the user performs a sliding operation, the originally visible pictures 1 and 2 become invisible, and some pictures enter the screen again and become visible.
[0058] Therefore, in a possible implementation, the image clearing condition can be determined based on the sliding condition.
[0059] If the cumulative sliding distance corresponding to the sliding direction of the target page in the sliding operation implemented through the target page is greater than the distance threshold, it is determined that the sliding operation implemented through the target page meets the image cleaning condition. Among them, the cumulative sliding distance corresponding to the sliding direction is greater than the distance threshold, indicating that the sliding operations implemented by the user all indicate sliding in the same direction, such as Figure 3 In the example, the user keeps sliding upwards. At this point, it can be assumed that the user's sliding intention is to view the next picture, so it can be assumed that the previously slid-out picture will not be slid back by the user. Therefore, it can be determined that the picture cleaning condition is met for subsequent processing.
[0060] In actual applications, the sliding of the RecyclerView of the page can be detected and the cumulative sliding distance of the RecyclerView can be recorded. For example, a distance threshold (such as a pixel value of twice the screen height) can be set. When the cumulative sliding distance reaches the distance threshold, it can be determined that the cleaning condition is met, and the images can be cleaned up according to a specific cleaning strategy. Among them, RecyclerView can refer to a list component provided by the target device, which can slide up and down, or slide left and right, etc.
[0061] It should also be noted that this application does not make any limitation on how to clean up. For ease of understanding, this application embodiment provides the following methods as examples:
[0062] In one possible implementation, based on the number of times the images stored in the image loading list array corresponding to the target page are loaded, images whose loading times are less than a threshold value can be determined as images to be cleared, and then the key value entries corresponding to the images to be cleared are deleted from the image loading list array corresponding to the target page.
[0063] Since in actual applications, the fewer the number of loading times, the less likely the image is to be loaded, it can be considered that the necessity of the image in the cache is not so high, so it can be cleared to free up memory. Based on this, a cleaning mechanism based on the number of loading times is provided to release memory in a timely manner and reduce memory usage. Exemplarily, the image with the least number of loading times can be determined as the image to be cleared. That is, a clearing strategy for the least used images is provided, which can more reasonably clear the least recently used image cache to achieve the purpose of reducing memory usage.
[0064] In another possible implementation, it is also possible to determine the pictures to be cleared from the pictures stored in the picture loading list array corresponding to the target page based on the number of times the pictures stored in the picture loading list array corresponding to the target page are loaded and the storage capacity limit corresponding to the picture loading list array corresponding to the target page, and then delete the key value entries corresponding to the pictures to be cleared from the picture loading list array corresponding to the target page.
[0065] Based on this, not only the number of loads is considered, but also the upper limit of the image load list array is considered to achieve better cleaning. Exemplarily, this can be the storage capacity limit M. When the maximum storage capacity limit M is reached, the images ranked in the last N positions in the number of loads can be cleared to release the cache occupied by N images. In this way, the N images can be only part of the image with the least number of loads, or all of the images with the least number of loads and part of the image with the second least number of loads, etc. It can be understood that it depends on the specific situation.
[0066] For ease of understanding, the embodiment of the present application takes the aforementioned least used image clearing strategy as an example and also provides a counting rule for the number of times an image is loaded, specifically:
[0067] In the process of responding to the sliding operation, that is, detecting the sliding of RecyclerView, when ViewHolder calls the bind() function, it starts loading the image to the ViewHolder for display, and saves the image Uri address to the corresponding Entry object, and the corresponding count is increased by one. And, when ViewHolder is recycled, the count of the image Uri is reduced by one. Specifically, Figure 3In this example, both item1 and item2 have slid out of the screen, but item2 has not been recycled yet, so the count of image 2 will not be reduced by one. However, item1 will trigger the recycling operation of RecyclerView, so the count of image 1 will be reduced by one. Figure 3 When item 1 in the example slides onto the screen again), the image Uri count is incremented by one. This is the same for each image. When the number of image Uri in the saved Map collection reaches the maximum capacity, the image Uri cleanup with a count of 0 is triggered, and these image Uri are removed from the Fresco cache. Based on this, system resources will not be occupied due to frequent memory cleanup, and there is no need to start a background scheduled cleanup task, reducing the waste of computing resources.
[0068] Corresponding to the counting rules in the above example, the embodiment of the present application also provides the following Figure 4 The schematic diagram of the calculation result of the least used rule of a picture shown in FIG. can be combined with the above example for explanation. Figure 2 Take the page Key(1) in the example as an example. Figure 4 The example is described as follows:
[0069] 1. Add picture 1, add the Entry1 object corresponding to picture 1 into the List array, and increase the internal count of the Entry1 object by one, count = 1.
[0070] 2. Add picture 2, add the Entry2 object corresponding to picture 2 into the List array, and increase the internal count of the Entry2 object by one, count = 1.
[0071] 3. Add picture 3, following the same steps as above.
[0072] 4. Add picture 4. Follow the same steps as above. If the ViewHolder recycling of picture 1 is triggered, reduce the calculation in the Entry1 object corresponding to picture 1 by one, and count = 0.
[0073] 5. Add picture 3. The Entry3 object corresponding to picture 3 is already in the List array. The count inside the Entry3 object is directly increased by 1, and count = 2. In addition, the count of picture 1 is 0 at this time, which meets the least recently used requirement. Therefore, if cache cleaning is triggered at this time, the cache of picture 1 will be directly cleared.
[0074] It should be noted that in Figure 4 In the example, the entries in the List array are sorted from large to small based on count, so that the pictures that need to be cleared can be quickly determined.
[0075] In addition to the cleaning mechanism described in the above example, in another possible implementation, in response to a close operation for closing a target page, the image loading list array corresponding to the target page can also be directly deleted. Based on this, when a page is closed, all image caches corresponding to the page are directly cleaned up by deleting the image loading list array, thereby achieving the purpose of freeing up memory.
[0076] During specific implementation, all image Uri in the Entry array corresponding to the page Key stored in the Map collection may be removed from the Fresco cache, and the Key, Value key-value pair may be removed from the Map.
[0077] It can be understood that it basically corresponds to the method embodiment, so the relevant parts can refer to the partial description of the method embodiment.
[0078] Figure 5 This is a structural diagram of a picture processing device provided in an embodiment of the present application, wherein the device includes an acquisition unit 501, a determination unit 502, a compression unit 503, and a loading unit 504:
[0079] The acquisition unit 501 is used to acquire the screen pixel density corresponding to the target device for running the target application, and to acquire the control size corresponding to the image loading control in the target application, wherein the image loading control is used to load the target image;
[0080] The determining unit 502 is used to determine the pixel size corresponding to the image loading control according to the screen pixel density and the control size;
[0081] The compression unit 503 is configured to compress the target image based on the pixel size to obtain a compressed image if the image pixel size of the target image exceeds the pixel size, and the image pixel size of the compressed image meets the pixel size;
[0082] The loading unit 504 is used to load the compressed image through the image loading control when the target application is running on the target device.
[0083] In a possible implementation manner, the compression unit is further configured to:
[0084] Splicing the pixel size into the image address corresponding to the target image to obtain a splicing address;
[0085] If the image pixel size of the target image exceeds the pixel size, the target image is compressed based on the pixel size carried in the splicing address to obtain the compressed image.
[0086] In a possible implementation, the loading unit is further used for:
[0087] When the target application is running on the target device, the compressed image is loaded through the image loading control based on the image address corresponding to the compressed image.
[0088] In a possible implementation, the device further includes a storage unit and a cleaning unit:
[0089] The storage unit is used to store a key value entry corresponding to the compressed picture in a picture loading set corresponding to the target application when loading the compressed picture, wherein the key value entry includes a picture address of the compressed picture and a number of times the compressed picture is loaded;
[0090] The cleaning unit is used to clean up the pictures stored in the picture loading set based on the number of times the pictures stored in the picture loading set are loaded in response to the sliding operation implemented by the target application satisfying the picture cleaning condition.
[0091] In a possible implementation, if the target page of the target application includes the image loading control, the image loading set includes an image loading list array corresponding to each page in the target application, and different pages correspond to different image loading list arrays, the storage unit is further used to:
[0092] When loading the compressed image, storing the key value entry corresponding to the target image in the image loading list array corresponding to the target page;
[0093] The cleaning unit is also used to clean up the pictures stored in the picture loading list array corresponding to the target page based on the number of loads of the pictures stored in the picture loading list array corresponding to the target page in response to the sliding operation implemented through the target page satisfying the picture cleaning condition.
[0094] In a possible implementation manner, the determining unit is further configured to:
[0095] If the sliding operation implemented through the target page indicates that the accumulated sliding distance corresponding to the sliding direction corresponding to the target page is greater than a distance threshold, it is determined that the sliding operation implemented through the target page satisfies the image clearing condition.
[0096] In a possible implementation, the cleaning unit is further used for:
[0097] In response to a close operation for closing the target page, the image loading list array corresponding to the target page is deleted.
[0098] In a possible implementation, the cleaning unit is further used for:
[0099] Based on the number of times the images stored in the image loading list array corresponding to the target page are loaded, determining the images whose number of times of loading is less than a number threshold as images to be cleared;
[0100] Delete the key value entry corresponding to the image to be cleared from the image loading list array corresponding to the target page.
[0101] It can be seen from the above technical solution that first, the screen pixel density corresponding to the target device for running the target application is obtained, and the control size corresponding to the picture loading control in the target application is obtained, and the picture loading control is used to load the target picture. Then, the pixel size corresponding to the picture loading control can be determined according to the screen pixel density and the control size. Among them, the screen pixel density can reflect the screen display performance of the target device, and specifically can reflect the number of pixels that can be displayed in an area of a unit size in the screen of the target device. And the control size can reflect the size of the area used to load the target picture, so the pixel size determined based on the two can reflect the number of pixels that can be displayed in the area identified by the picture loading control. Then, if the pixel size of the target picture exceeds the pixel size corresponding to the picture loading control, it indicates that the target picture at this time is too large, and the entire target picture cannot be fully loaded through the picture loading control. At this time, the target picture can be compressed based on the pixel size to obtain a compressed picture, and the pixel size of the compressed picture meets the pixel size. Finally, when the target application runs on the target device, the compressed picture can be loaded through the picture loading control. Based on this, when the image loading control cannot completely load the entire target image, the target image is replaced by a compressed image that meets the pixel size through compression processing. Since the pixel size of the compressed image is smaller than the pixel size of the target image, it is helpful to reduce memory usage. And the pixel size of the image loading control is determined based on the control size and the screen pixel density, so this application can be adapted to different image loading controls and image loading requirements on different devices, with higher versatility, and can be flexibly adapted to different image loading scenarios to reduce memory usage.
[0102] In another aspect, an embodiment of the present application provides a computer device, the computer device comprising a processor and a memory:
[0103] The memory is used to store program code and transmit the program code to the processor;
[0104] The processor is used to execute the image processing method provided in the above embodiment according to the instructions in the program code.
[0105] The computer device may include a terminal device or a server, and the aforementioned image processing apparatus may be configured in the computer device.
[0106] On the other hand, an embodiment of the present application further provides a storage medium, wherein the storage medium is used to store a computer program, and the computer program is used to execute the image processing method provided by the above embodiment.
[0107] In addition, an embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the image processing method provided in the above embodiment.
[0108] A person of ordinary skill in the art can understand that: all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium can be at least one of the following media: read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc., various media that can store program codes.
[0109] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0110] It should be noted that, in this article, relational terms such as "first" and "second", etc. (if any) are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0111] The above is a detailed introduction to an image processing method and related devices provided by the embodiment of the present application. The principles and implementation methods of the present application are described in detail using specific examples herein. The description of the above embodiments is only used to help understand the method of the present application. At the same time, for those skilled in the art, according to the method of the present application, there will be changes in the specific implementation methods and application scopes.
[0112] In summary, the content of this specification should not be understood as limiting the present application, and any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in this application should be included in the protection scope of this application. Moreover, based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations.
Claims
1. A method for processing an image, characterized in that: The method comprises: Obtaining a screen pixel density corresponding to a target device for running a target application, and obtaining a control size corresponding to an image loading control in the target application, wherein the image loading control is used to load a target image; Determine the pixel size corresponding to the image loading control according to the screen pixel density and the control size; If the image pixel size of the target image exceeds the pixel size, compressing the target image based on the pixel size to obtain a compressed image, wherein the image pixel size of the compressed image meets the pixel size; When the target application is running on the target device, the compressed image is loaded through the image loading control.
2. The method according to claim 1, characterized in that If the pixel size of the target image exceeds the pixel size, compressing the target image based on the pixel size to obtain a compressed image includes: Splicing the pixel size into the image address corresponding to the target image to obtain a splicing address; If the image pixel size of the target image exceeds the pixel size, the target image is compressed based on the pixel size carried in the splicing address to obtain the compressed image.
3. The method according to claim 2, characterized in that When the target application is running on the target device, loading the compressed image through the image loading control includes: When the target application is running on the target device, the compressed image is loaded through the image loading control based on the image address corresponding to the compressed image.
4. The method according to claim 1, characterized in that The method further comprises: When loading the compressed image, storing a key value entry corresponding to the compressed image in a picture loading set corresponding to the target application, the key value entry including a picture address of the compressed image and a number of times the compressed image is loaded; In response to a sliding operation implemented by the target application satisfying a picture clearing condition, the pictures stored in the picture loading set are cleared based on the number of times the pictures stored in the picture loading set are loaded.
5. The method according to claim 4, characterized in that If the target page of the target application includes the image loading control, the image loading set includes an image loading list array corresponding to each page in the target application, and different pages correspond to different image loading list arrays. When loading the compressed image, the key value entry corresponding to the target image is stored in the image loading set corresponding to the target application, including: When loading the compressed image, storing the key value entry corresponding to the target image in the image loading list array corresponding to the target page; In response to the sliding operation implemented by the target application satisfying the image clearing condition, based on the number of times the images stored in the image loading set are loaded, clearing the images stored in the image loading set, including: In response to the sliding operation implemented through the target page satisfying the image clearing condition, the images stored in the image loading list array corresponding to the target page are cleared based on the number of times the images stored in the image loading list array corresponding to the target page are loaded.
6. The method according to claim 5, characterized in that The method further comprises: If the sliding operation implemented through the target page indicates that the accumulated sliding distance corresponding to the sliding direction corresponding to the target page is greater than a distance threshold, it is determined that the sliding operation implemented through the target page satisfies the image clearing condition.
7. The method according to claim 5, characterized in that The method further comprises: In response to a close operation for closing the target page, the image loading list array corresponding to the target page is deleted.
8. The method according to claim 5, characterized in that The cleaning of the images stored in the image loading list array corresponding to the target page based on the number of times the images stored in the image loading list array corresponding to the target page are loaded includes: Based on the number of times the images stored in the image loading list array corresponding to the target page are loaded, determining the images whose number of times of loading is less than a number threshold as images to be cleared; Delete the key value entry corresponding to the image to be cleared from the image loading list array corresponding to the target page.
9. A picture processing device, characterized in that: The device comprises an acquisition unit, a determination unit, a compression unit and a loading unit: The acquisition unit is used to acquire the screen pixel density corresponding to the target device for running the target application, and to acquire the control size corresponding to the picture loading control in the target application, wherein the picture loading control is used to load the target picture; The determining unit is used to determine the pixel size corresponding to the image loading control according to the screen pixel density and the control size; The compression unit is configured to compress the target image based on the pixel size to obtain a compressed image if the image pixel size of the target image exceeds the pixel size, and the image pixel size of the compressed image meets the pixel size; The loading unit is used to load the compressed image through the image loading control when the target application is running on the target device.
10. A computer device, characterized in that: The computer device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the method according to any one of claims 1 to 8 according to the instructions in the program code.