CN106598679B - Method and device for loading picture resources - Google Patents

Method and device for loading picture resources Download PDF

Info

Publication number
CN106598679B
CN106598679B CN201611189784.2A CN201611189784A CN106598679B CN 106598679 B CN106598679 B CN 106598679B CN 201611189784 A CN201611189784 A CN 201611189784A CN 106598679 B CN106598679 B CN 106598679B
Authority
CN
China
Prior art keywords
picture
resource
loading
background
bitmap
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611189784.2A
Other languages
Chinese (zh)
Other versions
CN106598679A (en
Inventor
杨德立
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201611189784.2A priority Critical patent/CN106598679B/en
Publication of CN106598679A publication Critical patent/CN106598679A/en
Priority to PCT/CN2017/117675 priority patent/WO2018113725A1/en
Application granted granted Critical
Publication of CN106598679B publication Critical patent/CN106598679B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)
  • Telephone Function (AREA)

Abstract

The invention provides a method and a device for loading picture resources, wherein the method comprises the following steps: packaging a loading program set by a picture background and a loading program displayed by picture content into a picture resource loading class, and packaging a resource management interface for the picture resource loading class; thus, the resource management interface comprises two loaders: a loading program set for the picture background and a loading program for displaying the picture content; when the picture resources need to be loaded, no matter picture background setting or picture content display is loaded, the business layer can call the corresponding picture resource loading classes through the resource management interface, and load the corresponding picture background and the picture content display together, so that the resource loading process is optimized, and the cost of resource loading is reduced.

Description

Method and device for loading picture resources
Technical Field
The invention belongs to the technical field of resource loading, and particularly relates to a method and a device for loading picture resources.
Background
With the continuous development of electronic products, the intelligent terminal has become a necessary electronic product for human beings basically. The current mainstream terminal (such as a mobile phone, a tablet computer, etc.) operating system includes: android systems and IOS systems.
In the prior art, for a version before the 3.0 version of the Android system, when picture resources are loaded, a default resource loading method of the system is usually used for loading pictures, but the default resource loading method of the system cannot uniformly manage the loading of the picture resources when the picture resources are loaded, so that the resource loading process is complicated, and the cost of resource loading is increased.
Disclosure of Invention
Aiming at the problems in the prior art, the embodiment of the invention provides a method and a device for loading picture resources, which are used for solving the technical problem that when the picture resources are loaded in the versions below the 3.0 version of the Android system in the prior art, the loading of the picture resources cannot be uniformly managed.
The invention discloses a method for loading picture resources, which comprises the following steps:
Packaging a loading program set by the picture background and a loading program displayed by the picture content into a picture resource loading class;
Packaging a resource management interface for the picture resource loading class;
And calling the corresponding picture resource loading class through the resource management interface, and loading the corresponding picture background and picture content for display.
In the above scheme, after the picture resource is loaded, the method further includes: and storing the bit image pixel data generated in the loading process into a pre-established bitmap set.
In the above solution, after storing the bit image pixel data generated in the loading process into the bitmap set, the method further includes:
And calling a picture resource recovery program through the resource management interface according to a preset recovery time to recover useless picture resources.
In the above scheme, the recovery time is specifically when the picture on the interface is deleted.
In the above scheme, when the picture resource is loaded as the loading set for the picture background, the loading method specifically includes:
When the picture background is determined to be unloaded, acquiring the size of a view to be displayed, and judging whether the picture background needs to be compressed according to the size of the view;
When the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio;
Generating first bit image pixel data of the picture background according to the compressed picture background;
When the picture background is determined to be a common picture, generating a first bitmap object according to the first bitmap pixel data;
And assigning the first bitmap object to a view needing to display the picture background.
In the above solution, when it is determined that the picture background does not need to be compressed, the method further includes: and generating first bit image pixel data of the picture background according to the current picture background.
In the above scheme, in the loading process, the method further includes: and capturing the abnormal condition of insufficient memory, and giving up loading the current picture background resource when capturing the abnormal condition.
In the above scheme, when it is determined that the picture background is loaded, the method further includes: and calling first bit image pixel data of the picture background from the bitmap set.
In the foregoing solution, when it is determined that the picture background is a point nine picture, the method further includes:
Deleting the generated first bit map pixel data;
Searching and analyzing the picture background resource by using the resource ID to generate a second bitmap object;
And assigning the second bitmap object to the view needing to display the picture background.
In the above scheme, before loading the picture resource, the method further includes:
Judging the resource type according to the resource ID;
And when the resource type is determined to be the picture resource, calling a corresponding picture resource loading class through the resource management interface, and loading the corresponding picture resource.
in the above scheme, the resource types include a picture resource, a color value resource, and an XM L resource.
in the foregoing solution, when it is determined that the resource type is a color value resource and an XM L file resource, the method further includes:
Searching and analyzing corresponding resources by using the resource ID to generate a corresponding bitmap object;
And assigning the corresponding bitmap object to the view needing to display the picture background.
In the above scheme, when the loading of the picture resource is the loading of the picture content display, the loading method specifically includes:
When the picture content is determined to be not loaded, acquiring the size of a view to be displayed, and judging whether the picture content needs to be compressed or not according to the size of the view;
When the picture content display is determined to need to be compressed, compressing the picture content display according to a second compression ratio;
Generating second bit image pixel data displayed by the picture content according to the compressed picture content;
When the picture content display is determined not to be a dot-nine picture, generating a third bitmap object according to the second bitmap pixel data;
And assigning the third bitmap object to the view needing to display the picture content.
The invention also discloses a device for loading the picture resources, which comprises:
The first packaging unit is used for packaging a loading program set by the picture background and a loading program displayed by the picture content into the picture resource loading class;
The second packaging unit is used for packaging a resource management interface for the picture resource loading class;
And the calling unit is used for calling the corresponding picture resource loading class through the resource management interface, and loading the corresponding picture background and displaying the picture content.
In the foregoing solution, the apparatus further includes a storage unit, and after the picture resource is loaded, the storage unit is configured to: and storing the bit image pixel data generated in the loading process into a pre-established bitmap set.
In the above scheme, the calling unit is further configured to call a picture resource recovery program through the resource management interface according to a preset recovery time to recover useless picture resources.
In the above scheme, the recovery time is specifically when the picture on the interface is deleted.
In the foregoing solution, when the picture resource is loaded as a load set for a picture background, the first encapsulation unit includes:
The first determining subunit is used for determining that when the picture background is not loaded, the view size required to be displayed is obtained, and whether the picture background needs to be compressed is judged according to the view size; when the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio;
The first generation subunit is used for generating first-bit image pixel data of the picture background according to the compressed picture background;
The second determining subunit is configured to generate a first bitmap object according to the first bitmap pixel data when the picture background is determined to be an ordinary picture;
And the first assignment subunit is used for assigning the first bitmap object to the view needing to display the picture background.
In the foregoing solution, when the first determining subunit determines that the picture background does not need to be compressed, the first generating subunit is further configured to: and generating first bit image pixel data of the picture background according to the current picture background.
In the above solution, the first encapsulation unit further includes: and the first capturing subunit is used for capturing the abnormality of the insufficient memory in the loading process, and abandoning the loading of the picture background resource when the abnormality is captured.
In the above solution, the first encapsulation unit further includes: a first calling subunit, configured to call, from a bitmap set, first bitmap pixel data of the picture background when the first determining subunit determines that the picture background has been loaded.
In the above solution, the first encapsulation unit further includes: a first deletion subunit; when the second determining subunit determines that the picture background is a point nine picture,
The first deletion subunit is configured to delete the generated first bitmap pixel data;
The first generation subunit is further configured to search and analyze a picture background resource by using the resource ID to generate a second bitmap object;
The first assignment subunit is further configured to assign the second bitmap object to a view that needs to display a picture background.
In the above scheme, before loading the picture resource, the first determining subunit is further configured to determine a resource type according to the resource ID;
And when the resource type is determined to be the picture resource, the calling unit is used for calling the corresponding picture resource loading class through the resource management interface and loading the corresponding picture resource.
in the above scheme, the resource types include a picture resource, a color value resource, and an XM L resource.
in the above solution, the first encapsulation unit further includes a second generation subunit, wherein, when the first determination subunit determines that the resource type is a color value resource and an XM L file resource,
The second generating subunit is configured to search and analyze a corresponding resource using the resource ID, and generate a corresponding bitmap object;
The first assignment subunit is further configured to assign the corresponding bitmap object to a view that needs to display a picture background.
In the foregoing solution, when the loading of the picture resource is loading of picture content display, the first packaging unit further includes:
A third determining subunit, configured to obtain a view size to be displayed when it is determined that the display of the picture content is not loaded, and determine whether the display of the picture content needs to be compressed according to the view size; when the picture content display needs to be compressed, compressing the picture content display according to a second compression ratio;
The third generation subunit is used for generating second bit image pixel data displayed by the image content according to the compressed image content;
A fourth determining subunit, configured to determine that, when the picture content is displayed as an ordinary picture, a third bitmap object is generated according to the second bitmap pixel data;
And the second assignment subunit is used for assigning the third bitmap object to the view needing to display the picture content.
The invention provides a method and a device for loading picture resources, wherein the method comprises the following steps: packaging a loading program set by a picture background and a loading program displayed by picture content into a picture resource loading class, and packaging a resource management interface for the picture resource loading class; thus, the resource management interface comprises two loaders: a loading program set for the picture background and a loading program for displaying the picture content; when the picture resources need to be loaded, no matter picture background setting or picture content display is loaded, the business layer can call the corresponding picture resource loading classes through the resource management interface, and load the corresponding picture background and the picture content display together, so that the resource loading process is optimized, and the cost of resource loading is reduced.
Drawings
Fig. 1 is a schematic flowchart of a method for loading picture resources according to an embodiment of the present invention;
Fig. 2 is a schematic flowchart of a method for loading a picture background according to an embodiment of the present invention;
Fig. 3 is a schematic flow chart of a method for displaying content of a loaded picture according to an embodiment of the present invention;
Fig. 4 is a schematic structural diagram of an apparatus for loading picture resources according to an embodiment of the present invention;
Fig. 5 is a schematic structural diagram of a first packaging unit according to an embodiment of the present invention;
Fig. 6 is a schematic structural diagram of a first package unit according to an embodiment of the present invention.
Detailed Description
In order that those skilled in the art to which the present application pertains will more clearly understand the present application, exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Example one
The present embodiment provides a method for loading picture resources, as shown in fig. 1, the method includes:
S101, packaging a loading program set by the picture background and a loading program displayed by the picture content into a picture resource loading class.
In this step, the picture resource generally includes picture background setting and picture content display, and when the picture resource is loaded, the background setting and the picture content display need to be loaded, so that a loader program for the picture background setting and a loader program for the picture content display are encapsulated into a picture resource loading class Decode frontloader, which facilitates unified loading management.
after a loader set by a picture background and a loader displayed by picture content are packaged into a picture resource loading class Decode Drawablehelper, a Bitmap set m L eakBitmaps is also required to be established, so that the Bitmap of bit image pixel data generated in the loading process can be stored into the pre-established Bitmap set m L eakBitmaps.
Here, the implementation procedure for encapsulating the loader for setting the picture background and the loader for displaying the picture content into the picture resource loading class Decode Drawablehelper is as follows:
DecodeDrawableHelper.loadBackground
DecodeDrawableHelper.loadImage
The Background refers to a picture Background, and the Image refers to picture content display.
Specifically, when the picture resource is loaded as the loading set for the picture background, referring to fig. 2, the loading method corresponding to decoderwablehelper.
S201, receiving the resource, and judging whether the resource type is a picture resource according to the resource ID.
here, the different resource types correspond to different resource IDs, and after receiving the resource, when the resource is determined to be a picture background resource according to the resource ID, step S202 is performed, and when the resource is determined to be a color value resource and an XM L resource, step S203 is performed, wherein the resource types include a picture resource, a color value resource, and an XM L resource, the picture resource may include a common picture and a pointnine picture, and the color value resource includes color value types such as RGB8 and RGB 4.
S202, judging whether the picture background is loaded, and executing the step S204 when the picture background is determined not to be loaded. When the picture background is loaded, step S205 is executed.
S203, when the resources are determined to be color value resources and XM L resources, generating corresponding bitmap objects according to the color value resources and resource IDs corresponding to XM L, and assigning the corresponding bitmap objects to the views needing to display the background.
Specifically, a corresponding bitmap object Drawable is acquired in a resources.getDrawable (reset) mode, and is assigned to the View View, so that the View View can display corresponding resources. Wherein the resId refers to a resource ID.
Here, before assigning the bitmap object Drawable to the View, the method further includes:
judging whether SDK _ INT in the system is larger than 16, when the SDK _ INT is larger than or equal to 16, calling setBackward (Drawable) method by View to obtain a bitmap object Drawable, and assigning a background by using the bitmap object Drawable so as to display corresponding resources, and when the SDK _ INT is smaller than 16, calling setBackward (Drawable) method by View to obtain the bitmap object Drawable, and assigning a background by using the bitmap object Drawable so as to display corresponding resources.
S204, acquiring the View size to be displayed and the size of a picture background, and judging whether the picture background needs to be compressed according to the View size; when the picture background needs to be compressed, executing step 206; when the picture background does not need to be compressed, step 207 is performed.
Here, the size of the picture background obtained in this step is to reduce memory usage, and the specific implementation manner is as follows: and setting whether to acquire the value of the boundary injust decoderbounds as true, and when the value is set as true, acquiring the length, width and height information of the picture background only in the process of loading the picture background without really analyzing the picture background. After reading the size of the picture background, the value of injustdecodedpoints is set to false.
S205, when it is determined that the picture background has been loaded, calling a first Bitmap of Bitmap data Bitmap of the picture background from the Bitmap set m L eakBitmaps, where in order to reduce the memory occupied by the first Bitmap of Bitmap data Bitmap, in this embodiment, one pixel in the first Bitmap of Bitmap data Bitmap is set to occupy 2 bytes, for example, the loading format of the first Bitmap of Bitmap may be set to Bitmap.
S206, compressing the picture background according to a first compression ratio, generating first-bit image pixel data Bitmap of the picture background according to the compressed picture background after compressing the picture background; wherein the first compression ratio is calculated according to the background size and the view size of the picture.
S207, generating first-bit map pixel data Bitmap of the picture background according to the current picture background.
S208, after the first bit image pixel data Bitmap of the image background is generated, caching the first bit image pixel data Bitmap into a Bitmap set m L eakBitmaps, judging whether the image background is a point nine image, if so, executing the step S209, and if so, executing the step S210.
S209, when the background of the picture is determined to be a common picture, generating a first bitmap object Drawable according to the first bitmap pixel data; and assigning the first bitmap object Drawable to a View View needing to display the picture background, so that the View View can display the picture background.
S210, deleting the generated first Bitmap when the picture background is determined to be a dot nine picture; searching and analyzing the picture background resource by using the resource ID to generate a second bitmap object Drawable; and assigning the second bitmap object Drawable to the View View needing to display the picture background. Here, since the point nine picture is a picture type specifically supported by the Android system, if the point nine picture is a picture, repeated contents are filled according to a preset horizontal and vertical iteration region in the picture during drawing. Here, if the first Bitmap object Drawable is acquired in such a manner that the first Bitmap object Drawable is generated directly from the first Bitmap pixel data Bitmap, the attribute of the dot nine map is overwritten. Therefore, when the picture background is the point nine picture, the generated first Bitmap is deleted.
In the loading process, in order to further reduce the cost Of resource loading, an exception capture can be added by taking a resource loading class as a unit, an Out Of Memory (OOM) exception is captured by a Try and Catch parcel, and when the exception occurs, the current picture background resource is abandoned and loaded so as to avoid system application crash caused by the shortage Of the memory.
And finishing the loading process of the picture background setting.
Correspondingly, when the picture resource is loaded as the loading of the picture content display, referring to fig. 3, the loading method corresponding to the decoderwablehelper.loadimage is as follows:
S301, receiving the resource and judging the resource type according to the resource ID.
here, the different resource types correspond to different resource IDs, and after receiving the resource, when determining that the resource is a picture content display resource according to the resource IDs, step S302 is performed, and when determining that the resource is a color value resource and an XM L resource, step S303 is performed, wherein the resource types include a picture resource, a color value resource, and an XM L resource, the picture resource may include a common picture and a pointnine picture, and the color value resource includes color value types such as RGB8 and RGB 4.
S302, judging whether the picture content display is loaded or not, and executing the step S304 when the picture content display is determined not to be loaded. When the picture content display is loaded, step S305 is executed.
and S303, when the resources are determined to be color value resources and XM L resources, generating corresponding bitmap objects according to the color value resources and the resource IDs corresponding to XM L.
Specifically, a corresponding bitmap object Drawable is obtained in a resources.getDrawable (resId) mode, and the bitmap object is assigned to a View needing content display by an ImageView.setImageDrawable method, so that the View View can display corresponding resources. Wherein the resId refers to a resource ID.
S304, acquiring the View size to be displayed and the display size of the picture content, and judging whether the picture content display needs to be compressed according to the View size; when the picture content display needs to be compressed, executing step 306; when the picture content display does not require compression, step 307 is executed.
Here, the size of the picture content display obtained in this step is to reduce memory usage, and the specific implementation manner is as follows: and setting whether to acquire only the boundary inJustDecodeBounds as true, and when the boundary inJustDecodeBounds is set as true, acquiring only the length, width and height information of the picture content display in the process of loading the picture background, but not really analyzing the picture content display. After the size of the picture content display is read, inJustDecodeBounds is set as false.
S305, when it is determined that the picture content display has been loaded, calling a second Bitmap of Bitmap data Bitmap displayed from the Bitmap set m L eakBitmaps, where in order to reduce the memory occupied by the second Bitmap of Bitmap data Bitmap, in this embodiment, one pixel in the second Bitmap of Bitmap is set to occupy 2 bytes, for example, the loading format of the second Bitmap may be Bitmap.
S306, compressing the picture background according to a second compression ratio, displaying and compressing the picture content, and displaying and generating second-bit image pixel data Bitmap displayed by the picture content according to the compressed picture content; wherein the second compression ratio is calculated according to the picture content display size and the view size.
S307, second Bitmap displayed by the picture content is generated according to the current picture content.
S308, after second Bitmap of image pixel data displayed by the image content is generated, caching the second Bitmap into a Bitmap set, and judging whether the image content is displayed as a dot-nine image, if so, executing the step S309; if it is determined that the picture content is displayed as the point nine picture, step S310 is performed.
S309, when the picture content is determined to be displayed as a common picture, generating a third Bitmap object Drawable according to the second Bitmap pixel data Bitmap; and assigning the third bitmap object Draable to the View View needing to display the picture content, so that the View View can display the picture content.
S310, deleting the generated second Bitmap when the picture content is determined to be displayed as a dot nine picture; searching and analyzing the picture content display resource by using the resource ID to generate a fourth picture object; and assigning the fourth graph object Drawable to a View View needing to display the content of the graph. Here, since the point nine picture is a picture type specifically supported by the Android system, if the point nine picture is a picture, repeated contents are filled according to a preset horizontal and vertical iteration region in the picture during drawing. Here, if the third Bitmap object Drawable is acquired in such a manner that the third Bitmap object Drawable is generated directly from the second Bitmap data Bitmap, the attribute of the dot nine map is overwritten. Therefore, when the picture content display is a point nine picture, the generated second Bitmap pixel data Bitmap needs to be deleted.
In the loading process, in order to further reduce the cost Of resource loading, an exception capture can be added by taking a resource loading class as a unit, an Out Of Memory (OOM) exception is captured by a Try and Catch parcel, and when the exception is captured, the current picture resource is abandoned and loaded so as to avoid system application crash caused by insufficient memory.
And the loading process of the picture content display is finished.
It should be noted that, in the embodiment, when the picture background is loaded or the picture content is loaded for display, the same resource is loaded only once in the resource loading class, so that the repeated loading of the resource is effectively reduced, and the phenomenon of unstable loading process caused by memory jitter due to the repeated loading of the resource is avoided.
further, in order to recover useless picture resources in the bitmap set m L eakBitmaps, achieve controllability of memory management, and avoid application collapse due to insufficient memory, in this embodiment, after a loader set in a picture background and a loader displayed with picture content are packaged into a picture resource loading class, a program releaseSrc () for recovering picture resources is further packaged into the picture resource loading class, and the program for recovering picture resources and the program for loading picture resources share a resource management interface, where the program releaseSrc () for recovering picture resources is specifically implemented as follows:
Figure BDA0001186965490000121
here, when a recovery timing of a preset picture resource is triggered, a resource recovery program is called through the resource management interface to cyclically execute a recycle, so as to recover useless first-bit map pixel data bitmaps and first-bit map pixel data bitmaps in the Bitmap set m L eakBitmaps.
S102, packaging a resource management interface for the picture resource loading class.
After a loading program set in a picture background, a loading program displayed in picture content and a recovery program of a picture resource are packaged into a picture resource loading class, a resource management interface IDecodeDrawablehelper is also packaged for the picture resource loading class, and when the picture resource is required to be loaded or recovered, the picture resource loading program in the resource loading class can be called to load the picture resource only through the resource management interface, or the picture resource recovery program is called through the resource management interface to recover the picture resource. Therefore, the picture background setting, the picture content displaying and the picture resource recycling can be realized through the same resource management interface, and the unified management of the picture resource loading and recycling is realized.
Specifically, the encapsulation process of the resource management interface IDecodeDrawableHelper is as follows:
Figure BDA0001186965490000131
It can be seen that under the resource management interface idecodedrawableherper, two methods are included: the first is getHelper, which means to obtain the resource loading method under the encapsulated loading class; the second is releaseSrc, which refers to a method for recovering resources.
S103, calling a corresponding picture resource loading class through the resource management interface, and loading a corresponding picture background and displaying the picture content.
In this step, when the loading program set for the picture background and the loading program displayed by the picture content are packaged into the picture resource loading class; and after encapsulating the resource management interface IDecodeDrawablehelper corresponding to the picture resource loading class; the corresponding image resource loading class can be called through the resource management interface idecodedrawablebopper, and the corresponding image background and image content display are loaded, wherein the specific loading method can be seen in steps 201 to 210 and steps 201 to 210; or calling a picture resource recycling program through the resource management interface idecodedrawableborrer according to a preset recycling time to recycle useless picture resources, where a specific resource recycling method may be referred to in step S101.
In practical applications, the method for loading and recovering the picture resources described in step S101 may be applied to any View, View group and base Activity, and taking the base Activity of the Activity in a browser as an example, the method for loading and recovering the picture resources is specifically implemented as follows:
The method for obtaining the picture resource loading under the packaged picture resource loading class comprises the following steps:
Figure BDA0001186965490000141
In the loading process, when the interface picture is deleted, namely, a resource recycling method releaseSrc is called to recycle picture resources in Activity on destroy, and the program implementation in the calling process is as follows:
Figure BDA0001186965490000142
In this way, in the base activity and the class inherited from the base activity, when the picture resource is loaded, the picture background setting is loaded only by calling getHelper (), loadBackground, or the picture content display is loaded by calling gethelper.loadimage; when the picture resources are recovered, the releaseSrc can be called to recover the useless picture resources as long as the recovery time is triggered.
Example two
Corresponding to the first embodiment, this embodiment further provides a device for loading picture resources, as shown in fig. 4, the device includes: a first packaging unit 41, a second packaging unit 42, a calling unit 43 and a storage unit 445; wherein the content of the first and second substances,
The first encapsulating unit 41 is configured to encapsulate a loader set in the picture background and a loader displayed in the picture content into a picture resource loader; the picture resource generally comprises picture background setting and picture content display, and when the picture resource is loaded, the background setting and the picture content display need to be loaded, so that a loader program for the picture background setting and a loader program for the picture content display are packaged into a picture resource loading class Decode Drawablehelper, and unified loading management is facilitated.
after the first encapsulating unit 41 encapsulates the loader set by the picture background and the loader displayed by the picture content into the picture resource loading class Decode databarrier helper, a Bitmap set m L eak bitmaps needs to be created, and the storage unit 44 stores the Bitmap generated in the loading process into the Bitmap set m L eak bitmaps created in advance.
Here, the first encapsulating unit 41 encapsulates the loader of the picture background setting and the loader of the picture content display to the picture resource loader class Decode drain wallpaper helper as follows:
DecodeDrawableHelper.loadBackground
DecodeDrawableHelper.loadImage
The Background refers to a picture Background, and the Image refers to picture content display.
Specifically, referring to fig. 5, the first packaging unit 41 includes: a first determining subunit 51, a first calling subunit 52, a first generating subunit 53, a second determining subunit 54, a first assigning subunit 55, a first deleting subunit 56, a second generating subunit 57, and a first capturing subunit 58; wherein the content of the first and second substances,
when the picture resource is loaded as the picture background setting, the first determining subunit 51 is configured to receive the resource and determine the resource type according to the resource ID, where different resource types correspond to different resource IDs, and thus the resource type may be determined according to the resource ID, where the resource type includes a picture resource, a color value resource, and an XM L resource, the picture resource may include a normal picture and a dot-nine picture, and the color value resource may include color value types such as RGB8 and RGB 4.
When the first determining subunit 51 determines that the resource is a picture background resource, it is further required to determine whether a picture background is loaded, and when it is determined that the picture background is not loaded, obtain a View size to be displayed and a size of the picture background, and determine whether the picture background is required to be compressed according to the View size. And when the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio. Here, the first determining subunit 51 obtains the size of the picture background to reduce the memory usage, and the specific implementation manner is: the first determining subunit 51 sets whether to obtain only the value of the boundary injustdecodedpoints as true, and when the value is set as true, in the process of loading the picture background, only the length, width and height information of the picture background is obtained, and the picture background is not really analyzed. When the first determining subunit 51 reads the size of the picture background, inJustDecodeBounds is set to false.
further, when the first determining subunit 51 determines that the picture background is loaded, the first calling subunit 52 is configured to call the first Bitmap of the picture background from the Bitmap set m L eakBitmaps, where, in order to reduce the memory occupied by the first Bitmap, in this embodiment, one pixel in the first Bitmap is set to occupy 2 bytes, for example, the loading format of the first Bitmap may be Bitmap.
When the first determining subunit 51 determines that the picture background does not need to be compressed, the first generating subunit 53 is further configured to generate the first Bitmap of Bitmap pixel data of the picture background according to the current picture background.
after the first generating subunit 53 generates the first Bitmap of the picture background according to the current picture background, the storage unit 44 caches the first Bitmap of Bitmap in the Bitmap set m L eakBitmaps.
After the first generating subunit 53 generates the first bit of image pixel data Bitmap of the image background according to the current image background, the second determining subunit 54 is configured to determine whether the image background is a point nine image, and if it is determined that the image background is an ordinary image, further configured to generate a first bit of image object Drawable according to the first bit of image pixel data Bitmap, and the first assigning subunit 55 assigns the first bit of image object Drawable to the View that needs to display the image background, so that the View can display the image background.
When the second determining subunit 54 determines that the picture background is a point nine picture, the first deleting subunit 56 is configured to delete the generated first Bitmap; the first generating subunit 53 is further configured to search and analyze a picture background resource by using the resource ID, and generate a second bitmap object; the first assigning subunit 55 is further configured to assign the second bitmap object to the View that is to display the picture background. Here, since the point nine picture is a picture type specifically supported by the Android system, if the point nine picture is a picture, repeated contents are filled according to a preset horizontal and vertical iteration region in the picture during drawing. Here, if the first Bitmap object Drawable is acquired directly from the first Bitmap pixel data Bitmap to first Bitmap object Drawable, the attribute of the dot nine map is overwritten. Therefore, when the picture background is the point nine picture, the generated first Bitmap is deleted.
further, when the first determining subunit 51 determines that the resource is a color value resource and an XM L resource, the second generating subunit 57 is further configured to generate a corresponding bitmap object according to the color value resource and a resource ID corresponding to the XM L, and the first assigning subunit 55 is further configured to assign the corresponding bitmap object to a view that needs to display a background.
specifically, when the first determining subunit 51 determines that the resource is a color value resource and an XM L resource, the second generating subunit 57 obtains a corresponding bitmap object Drawable in a resources.
here, before the first assigning subunit 55 assigns the bitmap object Drawable to the View, the first determining subunit 51 is further configured to determine whether SDK _ INT in the system is greater than 16, when determining that the SDK _ INT is greater than or equal to 16, the View calls a setBackground (Drawable) method to acquire the bitmap object Drawable, assigns a background with the bitmap object Drawable, and thereby displays the corresponding resource, and when determining that the SDK _ INT is less than 16, the View calls a setBackgroundDrawable (Drawable) method to acquire the bitmap object Drawable, and assigns a background with the bitmap object Drawable, thereby displaying the corresponding resource.
In addition, during the loading process, in order to further reduce the cost of resource loading, the first encapsulation unit 41 further includes: the first capturing subunit 58 is used for adding exception capturing by taking a resource loading class as a unit, capturing Out Of Memory (OOM) exceptions by Try and Catch packages, and giving up loading Of the current picture background resource when the exceptions occur so as to avoid system application crash caused by insufficient memory.
Accordingly, when the picture resource is loaded as loading of picture content display, referring to fig. 6, the first packaging unit 41 further includes: a third determining subunit 61, a second calling subunit 62, a third generating subunit 63, a fourth determining subunit 64, a second assigning subunit 65, a second deleting subunit 66, a fourth generating subunit 67, and a second capturing subunit 68; wherein the content of the first and second substances,
The third determining subunit 61 is configured to receive the resource, and determine the resource type according to the resource ID. Here, different resource types correspond to different resource IDs, so that the resource types can be determined according to the resource IDs.
When the resource is received, the third determining subunit 61 determines, according to the resource ID, that the resource is a picture content display resource, determines whether the picture content display is loaded, and when it is determined that the picture content display is not loaded; acquiring the View size to be displayed and the display size of the picture content, and judging whether the picture content display needs to be compressed according to the View size; when the picture content display needs to be compressed, compressing the picture content display according to a second compression ratio, and generating second Bitmap of picture pixel data displayed by the picture content display according to the compressed picture content display after compressing the picture content display; wherein the second compression ratio is calculated according to the picture content display size and the view size. Here, the third determining subunit 61 obtains the size of the picture content display to reduce the memory usage, and the specific implementation manner is: and setting whether to acquire the value of the boundary injust decoderbounds as true, and acquiring only the length, width and height information of the picture content display in the process of loading the picture background when the value of the boundary injust decoderbounds is set as true, but not really analyzing the picture content display. After the size of the picture content display is read, the value of injustdecodedpoints is set to false.
when the third determining subunit 61 determines that the picture content display is loaded, the second calling subunit 62 is configured to call, from the Bitmap set m L eakBitmaps, the second Bitmap of the picture content display, where, in order to reduce the memory occupied by the second Bitmap, in this embodiment, one pixel in the second Bitmap is set to occupy 2 bytes, for example, the loading format of the second Bitmap may be Bitmap.
When the third determining subunit 61 determines that the picture content display does not need to be compressed, the third generating subunit 63 generates the second Bitmap of the picture background according to the current picture content display.
After the third generating subunit 63 generates the second Bitmap according to the second Bitmap data Bitmap displayed by the current picture content display picture content, the second Bitmap data Bitmap is cached in the Bitmap set, the fourth determining subunit 64 is configured to determine whether the picture content display is a point nine map, and if it is determined that the picture content display is an ordinary picture, the third generating subunit 63 is configured to generate a third Bitmap object draable according to the second Bitmap data; the second assigning subunit 65 assigns the third bitmap object draable to the View that needs to display the picture content, so that the View can display the picture content.
When the fourth determining subunit 64 determines that the picture content is displayed as a point nine picture, the second deleting subunit 66 is configured to delete the generated second Bitmap; the third generating subunit 63 is further configured to search and analyze a picture content display resource by using the resource ID, and generate a fourth picture object Drawable; the second assigning subunit 65 is further configured to assign the fourth graphics object to View which needs to display the graphics content. Here, since the point nine picture is a picture type supported particularly, if the point nine picture is a picture type supported particularly, repeated contents are filled according to a horizontal and vertical iteration region preset in the picture during drawing. Here, if the third Bitmap object Drawable is acquired in such a manner that the third Bitmap object Drawable is generated directly from the second Bitmap data Bitmap, the attribute of the dot nine map is overwritten. Therefore, when the picture content display is a point nine picture, the generated second Bitmap pixel data Bitmap needs to be deleted.
further, when the third determining subunit 61 determines that the resource is a color value resource and an XM L resource, the fourth generating subunit 67 is further configured to generate a corresponding bitmap object according to the color value resource and the resource ID corresponding to the XM L, and the second assigning subunit 65 is further configured to assign the corresponding bitmap object to the view that needs to display the content of the display picture.
specifically, when the third determining subunit 61 determines that the resource is a color value resource and an XM L resource, the fourth generating subunit 67 obtains a corresponding bitmap object Drawable in a resources.
In addition, during the loading process, in order to further reduce the cost of resource loading, the first encapsulation unit 41 further includes: and the second capturing subunit 68 is used for adding exception capturing by taking the resource loading class as a unit, capturing the out-of-memory OOM exception through Try and Catch packages, and giving up loading the current picture resource when the exception occurs so as to avoid system application crash caused by the out-of-memory.
It should be noted that, in the embodiment, when the picture background is loaded or the picture content is loaded for display, the same resource is loaded only once in the resource loading class, so that the repeated loading of the resource is effectively reduced, and the phenomenon of unstable loading process caused by memory jitter due to the repeated loading of the resource is avoided.
further, in order to recycle useless picture resources in the bitmap set m L eakBitmaps, achieve controllability of memory management, and avoid application collapse caused by insufficient memory, the first encapsulating unit 41 is further configured to encapsulate, after encapsulating a loader set in a picture background and a loader displayed in picture content into a picture resource loading class, a program releaseSrc () for recycling picture resources into the picture resource loading class, where the program for recycling picture resources and the program loaded in picture resources share a resource management interface, and the program releaseSrc () for recycling picture resources is specifically implemented as follows:
Figure BDA0001186965490000201
here, when a recovery timing of a preset picture resource is triggered, the recycle is executed in a loop manner to recover the first Bitmap and the first Bitmap which are useless in the Bitmap set m L eakBitmaps.
Further, after the first encapsulating unit 41 encapsulates the loader set in the picture background, the loader displayed in the picture content, and the recycle program of the picture resource into the picture resource loading class, the second encapsulating unit 42 is configured to encapsulate a resource management interface for the picture resource loading class.
Specifically, after the first encapsulating unit 41 encapsulates the loader set in the picture background, the loader displayed in the picture content, and the recycle program of the picture resource into the picture resource loader, a resource management interface idecodedrawable helper is further encapsulated for the picture resource loader, and when the picture resource needs to be loaded or recycled, the picture resource loader in the resource loader can be called to load the picture resource through the resource management interface, or the picture resource recycle program is called to recycle the picture resource through the resource management interface. Therefore, the picture background setting, the picture content displaying and the picture resource recycling can be realized through the same resource management interface, and the unified management of the picture resource loading and recycling is realized.
In particular, the second encapsulation unit 42 interfaces the resource management
Figure BDA0001186965490000211
It can be seen that under the resource management interface idecodedrawableherper, two methods are included: the first is getHelper, which means to obtain the resource loading method under the encapsulated loading class; the second is releaseSrc, which refers to a method for recovering resources.
When the first encapsulating unit 41 encapsulates the loader set for the picture background and the loader displayed for the picture content into the picture resource loader; after the second encapsulating unit 42 encapsulates the resource management interface idecodedewablehelper corresponding to the picture resource loading class, the calling unit 43 may call the corresponding picture resource loading class through the resource management interface, and load the corresponding picture background and the picture content for display. Specific loading procedures can be found above; or the calling unit 43 may also call a picture resource recycling program through the resource management interface idecodedwablehelper according to a preset recycling opportunity to recycle useless picture resources, and the specific resource recycling process may also be referred to above.
In practical applications, the above-described picture resource loading process and picture resource recovery process may be applied to any View, View group, and base class activities, where, taking the base class Activity of the Activity in a browser as an example, the picture resource loading process and the picture resource recovery process are specifically implemented as follows:
The method for obtaining the picture resource loading under the packaged picture resource loading class comprises the following steps:
Figure BDA0001186965490000221
In the loading process, when the interface picture is deleted, that is, in Activity on delete, the calling unit 43 may call a resource recovery method releaseSrc to recover the picture resource, where the program in the calling process is implemented as follows:
Figure BDA0001186965490000222
In this way, in the base activity and the class inherited from the base activity, when the picture resource is loaded, the picture background setting is loaded only by calling getHelper (), loadBackground, or the picture content display is loaded by calling gethelper.loadimage; when the picture resources are recovered, the releaseSrc can be called to recover the useless picture resources as long as the recovery time is triggered.
Through one or more embodiments of the present invention, the present invention has the following advantageous effects or advantages:
The invention discloses a method and a device for loading picture resources.A loading program set by a picture background and a loading program displayed by picture content are packaged into a picture resource loading class before the picture resources are loaded, and a resource management interface is packaged for the picture resource loading class; thus, the resource management interface comprises two loaders: a loading program set for the picture background and a loading program for displaying the picture content; when the picture resources need to be loaded, no matter picture background setting or picture content display is loaded, the business layer can call the corresponding picture resource loading classes through the resource management interface, and load the corresponding picture background and the picture content display together, so that the resource loading process is optimized, and the cost of resource loading is reduced. And moreover, exception capture is added by taking the resource loading class as a unit, so that the exception occurring in the loading process can be uniformly captured and processed, and the resource loading cost is further reduced.
When the picture background is loaded or the picture content is loaded and displayed, the same resources are loaded only once in the resource loading class, so that the repeated loading of the resources is effectively reduced, and the phenomenon of unstable loading process caused by memory jitter due to the repeated loading of the resources is avoided. In addition, the method stores the bit image pixel data generated in the loading process into the bitmap set by pre-establishing the bitmap set, realizes controllable memory management, encapsulates the resource recovery program into the resource loading class, adds the recovery time in the resource recovery program, and calls the resource recovery program through the same resource management interface to timely recover the useless image resources in the bitmap set when the recovery time is triggered, thereby realizing controllable resource recovery and fundamentally solving the OOM problem caused by insufficient native cache. And unified management of resource loading and recovery is realized.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components of a gateway, proxy server, system according to embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.
The invention discloses a1 method for loading picture resources, which is characterized by comprising the following steps:
Packaging a loading program set by the picture background and a loading program displayed by the picture content into a picture resource loading class;
Packaging a resource management interface for the picture resource loading class;
And calling a corresponding picture resource loading class through the resource management interface, and loading a corresponding picture background and displaying the picture content.
A2, the method of claim a1, wherein when the picture resource is loaded, the method further comprises: and storing the bit image pixel data generated in the loading process into a pre-established bitmap set.
A3, the method of claim a2, wherein after storing the bit-image-element data generated during loading into the bitmap collection, the method further comprises:
And calling a picture resource recovery program through the resource management interface according to a preset recovery time to recover useless picture resources.
A4, the method according to claim A3, wherein the recovery occasion is when a picture on the interface is deleted.
A5, the method of claim a1, wherein when the picture resource is loaded with a load set for a picture background, the loading method specifically comprises:
When the picture background is determined to be unloaded, acquiring the size of a view to be displayed, and judging whether the picture background needs to be compressed according to the size of the view;
When the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio;
Generating first bit image pixel data of the picture background according to the compressed picture background;
When the picture background is determined to be a common picture, generating a first bitmap object according to the first bitmap pixel data;
And assigning the first bitmap object to a view needing to display the picture background.
A6, the method of claim a5, wherein when it is determined that the picture background does not require compression, the method further comprises: and generating first bit image pixel data of the picture background according to the current picture background.
A7, the method of claim a5, wherein during loading, the method further comprises: and capturing the abnormal condition of insufficient memory, and giving up loading the current picture background resource when capturing the abnormal condition.
A8, the method of claim a5, wherein when it is determined that the picture background has been loaded, the method further comprises: and calling first bit image pixel data of the picture background from the bitmap set.
A9, the method of claim a5, wherein when it is determined that the picture background is a point nine picture, the method further comprises:
Deleting the generated first bit map pixel data;
Searching and analyzing the picture background resource by using the resource ID to generate a second bitmap object;
And assigning the second bitmap object to the view needing to display the picture background.
A10, the method of claim a5, wherein prior to loading the picture resource, the method further comprises:
Judging the resource type according to the resource ID;
And when the resource type is determined to be the picture resource, calling a corresponding picture resource loading class through the resource management interface, and loading the corresponding picture resource.
A11, the method of claim A10, wherein the resource types include a picture resource, a color value resource, and an XM L resource.
A12, the method of claim A11, wherein when determining that the resource type is a color value resource and an XM L file resource, the method further comprises:
Searching and analyzing corresponding resources by using the resource ID to generate a corresponding bitmap object;
And assigning the corresponding bitmap object to the view needing to display the picture background.
A13, the method of claim a5, wherein when the picture resource is loaded as a loading of picture content display, the loading method specifically comprises:
When the picture content is determined to be not loaded, acquiring the size of a view to be displayed, and judging whether the picture content needs to be compressed or not according to the size of the view;
When the picture content display is determined to need to be compressed, compressing the picture content display according to a second compression ratio;
Generating second bit image pixel data displayed by the picture content according to the compressed picture content;
When the picture content display is determined not to be a dot-nine picture, generating a third bitmap object according to the second bitmap pixel data;
And assigning the third bitmap object to the view needing to display the picture content.
B14, an apparatus for loading picture resources, the apparatus comprising:
The first packaging unit is used for packaging a loading program set by the picture background and a loading program displayed by the picture content into the picture resource loading class;
The second packaging unit is used for packaging a resource management interface for the picture resource loading class;
And the calling unit is used for calling the corresponding picture resource loading class through the resource management interface, and loading the corresponding picture background and displaying the picture content.
The apparatus according to claim B15 or claim B14, further comprising a storage unit, wherein when the picture resource is loaded, the storage unit is configured to: and storing the bit image pixel data generated in the loading process into a pre-established bitmap set.
B16, the apparatus according to claim B15, wherein the invoking unit is further configured to invoke a picture resource recycling program through the resource management interface according to a preset recycling opportunity to recycle useless picture resources.
B17, the device of claim B15, wherein the recovery occasion is when a picture on an interface is deleted.
B18, the apparatus according to claim B14, wherein when the picture resource is loaded as a load set for a picture background, the first encapsulating unit includes:
The first determining subunit is used for determining that when the picture background is not loaded, the view size required to be displayed is obtained, and whether the picture background needs to be compressed is judged according to the view size; when the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio;
The first generation subunit is used for generating first-bit image pixel data of the picture background according to the compressed picture background;
The second determining subunit is configured to generate a first bitmap object according to the first bitmap pixel data when the picture background is determined to be an ordinary picture;
And the first assignment subunit is used for assigning the first bitmap object to the view needing to display the picture background.
The apparatus of claim B18, wherein when the first determining subunit determines that the picture background does not require compression, the first generating subunit is further to: and generating first bit image pixel data of the picture background according to the current picture background.
B20, the apparatus of claim B18, wherein the first packaging unit further comprises: and the first capturing subunit is used for capturing the abnormality of the insufficient memory in the loading process, and abandoning the loading of the picture background resource when the abnormality is captured.
B21, the apparatus of claim B18, wherein the first packaging unit further comprises: a first calling subunit, configured to call, from a bitmap set, first bitmap pixel data of the picture background when the first determining subunit determines that the picture background has been loaded.
B22, the apparatus of claim B18, wherein the first packaging unit further comprises: a first deletion subunit; when the second determining subunit determines that the picture background is a point nine picture,
The first deletion subunit is configured to delete the generated first bitmap pixel data;
The first generation subunit is further configured to search and analyze a picture background resource by using the resource ID to generate a second bitmap object;
The first assignment subunit is further configured to assign the second bitmap object to a view that needs to display a picture background.
B23, the apparatus according to claim B14, wherein before the picture resource is loaded, the first determining subunit is further configured to determine a resource type according to the resource ID;
And when the resource type is determined to be the picture resource, the calling unit is used for calling the corresponding picture resource loading class through the resource management interface and loading the corresponding picture resource.
the apparatus of claim B23, wherein the resource types include a picture resource, a color value resource, and an XM L resource.
the apparatus of claim B23, wherein the first packing unit further comprises a second generating subunit, and wherein, when the first determining subunit determines that the resource type is color value resource and XM L file resource,
The second generating subunit is configured to search and analyze a corresponding resource using the resource ID, and generate a corresponding bitmap object;
The first assignment subunit is further configured to assign the corresponding bitmap object to a view that needs to display a picture background.
B26, the apparatus according to claim B18, wherein when the loading of the picture resource is loading of picture content display, the first encapsulating unit further includes:
A third determining subunit, configured to obtain a view size to be displayed when it is determined that the display of the picture content is not loaded, and determine whether the display of the picture content needs to be compressed according to the view size; when the picture content display needs to be compressed, compressing the picture content display according to a second compression ratio;
The third generation subunit is used for generating second bit image pixel data displayed by the image content according to the compressed image content;
A fourth determining subunit, configured to determine that, when the picture content is displayed as an ordinary picture, a third bitmap object is generated according to the second bitmap pixel data;
And the second assignment subunit is used for assigning the third bitmap object to the view needing to display the picture content.

Claims (26)

1. A method for loading picture resources, the method comprising:
Packaging a loading program set by the picture background and a loading program displayed by the picture content into a picture resource loading class;
Packaging a resource management interface for the picture resource loading class;
Calling a corresponding picture resource loading class through the resource management interface, and loading a corresponding picture background and picture content for display; wherein the content of the first and second substances,
And a picture resource recovery program is also packaged in the picture resource loading class, and the picture resource recovery program shares the resource management interface with the loading program set by the picture background and the loading program displayed by the picture content.
2. The method of claim 1, wherein after loading the picture resource, the method further comprises: and storing the bit image pixel data generated in the loading process into a pre-established bitmap set.
3. The method of claim 2, wherein after storing the bit-map pixel data generated during the loading into the set of bitmaps, the method further comprises:
And calling a picture resource recovery program through the resource management interface according to a preset recovery time to recover useless picture resources.
4. The method of claim 3, wherein the recycling opportunity is specifically when a picture on the interface is deleted.
5. The method of claim 1, wherein when the picture resource is loaded with a load set for a picture background, the loading method specifically comprises:
When the picture background is determined to be unloaded, acquiring the size of a view to be displayed, and judging whether the picture background needs to be compressed according to the size of the view;
When the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio;
Generating first bit image pixel data of the picture background according to the compressed picture background;
When the picture background is determined to be a common picture, generating a first bitmap object according to the first bitmap pixel data;
And assigning the first bitmap object to a view needing to display the picture background.
6. The method of claim 5, wherein when it is determined that the picture background does not require compression, the method further comprises: and generating first bit image pixel data of the picture background according to the current picture background.
7. The method of claim 5, wherein during loading, the method further comprises: and capturing the abnormal condition of insufficient memory, and giving up loading the current picture background resource when capturing the abnormal condition.
8. The method of claim 5, wherein when it is determined that the picture background has been loaded, the method further comprises: and calling first bit image pixel data of the picture background from the bitmap set.
9. The method of claim 5, wherein when the picture background is determined to be a point nine picture, the method further comprises:
Deleting the generated first bit map pixel data;
Searching and analyzing the picture background resource by using the resource ID to generate a second bitmap object;
And assigning the second bitmap object to the view needing to display the picture background.
10. The method of claim 5, wherein prior to loading the picture resource, the method further comprises:
Judging the resource type according to the resource ID;
And when the resource type is determined to be the picture resource, calling a corresponding picture resource loading class through the resource management interface, and loading the corresponding picture resource.
11. the method of claim 10, wherein the resource types include a picture resource, a color value resource, and an XM L resource.
12. the method of claim 11, wherein when determining that the resource type is a color value resource and an XM L file resource, the method further comprises:
Searching and analyzing corresponding resources by using the resource ID to generate a corresponding bitmap object;
And assigning the corresponding bitmap object to the view needing to display the picture background.
13. The method of claim 5, wherein when the loading of the picture resource is loading of picture content display, the loading method specifically comprises:
When the picture content is determined to be not loaded, acquiring the size of a view to be displayed, and judging whether the picture content needs to be compressed or not according to the size of the view;
When the picture content display is determined to need to be compressed, compressing the picture content display according to a second compression ratio;
Generating second bit image pixel data displayed by the picture content according to the compressed picture content;
When the picture content display is determined not to be a dot-nine picture, generating a third bitmap object according to the second bitmap pixel data;
And assigning the third bitmap object to the view needing to display the picture content.
14. An apparatus for loading picture resources, the apparatus comprising:
The first packaging unit is used for packaging a loading program set by the picture background and a loading program displayed by the picture content into the picture resource loading class;
The second packaging unit is used for packaging a resource management interface for the picture resource loading class;
The calling unit is used for calling the corresponding picture resource loading class through the resource management interface, and loading the corresponding picture background and displaying the picture content; wherein the content of the first and second substances,
And a picture resource recovery program is also packaged in the picture resource loading class, and the picture resource recovery program shares the resource management interface with the loading program set by the picture background and the loading program displayed by the picture content.
15. The apparatus as claimed in claim 14, further comprising a storage unit, wherein when the picture resource is loaded, the storage unit is configured to: and storing the bit image pixel data generated in the loading process into a pre-established bitmap set.
16. The apparatus of claim 15, wherein the calling unit is further to: and calling a picture resource recovery program through the resource management interface according to a preset recovery time to recover useless picture resources.
17. The apparatus of claim 15, wherein the recycling opportunity is specifically when a picture on the interface is deleted.
18. The apparatus of claim 14, wherein when the picture resource loads a load set for a picture background, the first packing unit comprises:
The first determining subunit is used for determining that when the picture background is not loaded, the view size required to be displayed is obtained, and whether the picture background needs to be compressed is judged according to the view size; when the picture background is determined to need to be compressed, compressing the picture background according to a first compression ratio;
The first generation subunit is used for generating first-bit image pixel data of the picture background according to the compressed picture background;
The second determining subunit is configured to generate a first bitmap object according to the first bitmap pixel data when the picture background is determined to be an ordinary picture;
And the first assignment subunit is used for assigning the first bitmap object to the view needing to display the picture background.
19. The apparatus of claim 18, wherein when the first determining subunit determines that the picture background does not require compression, the first generating subunit is further to: and generating first bit image pixel data of the picture background according to the current picture background.
20. The apparatus of claim 18, wherein the first packaging unit further comprises: and the first capturing subunit is used for capturing the abnormality of the insufficient memory in the loading process, and abandoning the loading of the picture background resource when the abnormality is captured.
21. The apparatus of claim 18, wherein the first packaging unit further comprises: a first calling subunit, configured to call, from a bitmap set, first bitmap pixel data of the picture background when the first determining subunit determines that the picture background has been loaded.
22. The apparatus of claim 18, wherein the first packaging unit further comprises: a first deletion subunit; when the second determining subunit determines that the picture background is a point nine picture,
The first deletion subunit is configured to delete the generated first bitmap pixel data;
The first generation subunit is further configured to search and analyze a picture background resource by using the resource ID to generate a second bitmap object;
The first assignment subunit is further configured to assign the second bitmap object to a view that needs to display a picture background.
23. The apparatus of claim 18, wherein, before loading the picture resource, the first determining subunit is further configured to determine a resource type according to the resource ID;
And when the resource type is determined to be the picture resource, the calling unit is used for calling the corresponding picture resource loading class through the resource management interface and loading the corresponding picture resource.
24. the apparatus of claim 23, wherein the resource types include a picture resource, a color value resource, and an XM L resource.
25. the apparatus of claim 18, wherein the first wrapper unit further comprises a second generating subunit, wherein, when the first determining subunit determines that the resource type is color value resource and XM L file resource,
The second generating subunit is configured to search and analyze a corresponding resource using the resource ID, and generate a corresponding bitmap object;
The first assignment subunit is further configured to assign the corresponding bitmap object to a view that needs to display a picture background.
26. The apparatus of claim 18, wherein when the loading of the picture resource is a loading of a picture content display, the first packaging unit further comprises:
A third determining subunit, configured to obtain a view size to be displayed when it is determined that the display of the picture content is not loaded, and determine whether the display of the picture content needs to be compressed according to the view size; when the picture content display needs to be compressed, compressing the picture content display according to a second compression ratio;
The third generation subunit is used for generating second bit image pixel data displayed by the image content according to the compressed image content;
A fourth determining subunit, configured to determine that, when the picture content is displayed as an ordinary picture, a third bitmap object is generated according to the second bitmap pixel data;
And the second assignment subunit is used for assigning the third bitmap object to the view needing to display the picture content.
CN201611189784.2A 2016-12-21 2016-12-21 Method and device for loading picture resources Active CN106598679B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201611189784.2A CN106598679B (en) 2016-12-21 2016-12-21 Method and device for loading picture resources
PCT/CN2017/117675 WO2018113725A1 (en) 2016-12-21 2017-12-21 Method and device for loading picture resource, and program and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611189784.2A CN106598679B (en) 2016-12-21 2016-12-21 Method and device for loading picture resources

Publications (2)

Publication Number Publication Date
CN106598679A CN106598679A (en) 2017-04-26
CN106598679B true CN106598679B (en) 2020-07-31

Family

ID=58600129

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611189784.2A Active CN106598679B (en) 2016-12-21 2016-12-21 Method and device for loading picture resources

Country Status (2)

Country Link
CN (1) CN106598679B (en)
WO (1) WO2018113725A1 (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106598679B (en) * 2016-12-21 2020-07-31 北京奇虎科技有限公司 Method and device for loading picture resources
CN107301053B (en) * 2017-07-04 2020-12-15 武汉斗鱼网络科技有限公司 Picture configuration method and device and electronic terminal
CN107491334B (en) * 2017-08-29 2020-12-15 四川长虹电器股份有限公司 Method for organizing and loading preloaded files
CN113254131A (en) * 2021-05-20 2021-08-13 北京有竹居网络技术有限公司 Page background display method and device
CN113256485B (en) * 2021-05-21 2024-01-30 百果园技术(新加坡)有限公司 Image stretching method, device, electronic equipment and storage medium
CN113419802B (en) * 2021-06-21 2022-08-05 网易(杭州)网络有限公司 Atlas generation method and apparatus, electronic device and storage medium
CN114090116A (en) * 2021-11-08 2022-02-25 芜湖雄狮汽车科技有限公司 Application method and device of vehicle-mounted equipment, vehicle and storage medium
CN114398124B (en) * 2021-12-31 2024-04-12 深圳市珍爱捷云信息技术有限公司 Point nine effect graph rendering method based on iOS system and related device thereof

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140366034A1 (en) * 2013-06-06 2014-12-11 Canon Kabushiki Kaisha Image processing apparatus, control method thereof and storage medium
CN105468368A (en) * 2015-11-23 2016-04-06 浪潮软件股份有限公司 Interface beautification method
CN106126650A (en) * 2016-06-24 2016-11-16 武汉斗鱼网络科技有限公司 A kind of Web page picture based on PHP extension supports system

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103902318A (en) * 2012-12-30 2014-07-02 青岛海尔软件有限公司 Android platform based image loading method
CN104182403B (en) * 2013-05-22 2018-07-13 阿里巴巴集团控股有限公司 A kind of loading method and equipment of pictorial information
CN103309749A (en) * 2013-06-25 2013-09-18 四川九洲电器集团有限责任公司 Internal memory release method of image resource based on Android system
CN105023285B (en) * 2014-04-25 2018-12-18 腾讯科技(深圳)有限公司 Picture method for splitting and device, picture loading method and device
CN104267996A (en) * 2014-09-29 2015-01-07 广州金山网络科技有限公司 Image resource processing method, device and terminal
CN105446763B (en) * 2014-09-30 2019-01-29 Tcl集团股份有限公司 A kind of method and system of picture load and display
CN104360871A (en) * 2014-10-12 2015-02-18 厦门雅基软件有限公司 Quick starting method for installation of cell phone games
CN104850440A (en) * 2015-05-25 2015-08-19 广州市久邦数码科技有限公司 Android system based resource loading method and system therefor
CN105511864A (en) * 2015-11-30 2016-04-20 青岛海信移动通信技术股份有限公司 Resource positioning method and device
CN106598679B (en) * 2016-12-21 2020-07-31 北京奇虎科技有限公司 Method and device for loading picture resources

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140366034A1 (en) * 2013-06-06 2014-12-11 Canon Kabushiki Kaisha Image processing apparatus, control method thereof and storage medium
CN105468368A (en) * 2015-11-23 2016-04-06 浪潮软件股份有限公司 Interface beautification method
CN106126650A (en) * 2016-06-24 2016-11-16 武汉斗鱼网络科技有限公司 A kind of Web page picture based on PHP extension supports system

Also Published As

Publication number Publication date
CN106598679A (en) 2017-04-26
WO2018113725A1 (en) 2018-06-28

Similar Documents

Publication Publication Date Title
CN106598679B (en) Method and device for loading picture resources
CN108845861B (en) Method and device for realizing virtual camera
CN108563517B (en) Calling method and device of system interface
CN109885324B (en) Processing method, device, terminal and storage medium of application program installation package
CN106598614B (en) Method and device for recycling picture resources
CN106295370B (en) Method and device for reinforcing Dynamic Link Library (DLL) file of installation package
CN108021671B (en) Page transparent processing method and device
CN107040584B (en) Method and device for downloading picture by client
CN107798064B (en) Page processing method, electronic device and computer readable storage medium
CN108052565B (en) Transparent processing method and device for page
CN108364324B (en) Image data processing method and device and electronic terminal
CN113885935A (en) Resource packaging method and device, electronic equipment and computer readable storage medium
CN105138399A (en) Cross-platform mobile Web application runtime engine
CN113038141B (en) Video frame processing method and electronic equipment
CN106293658B (en) Interface component generation method and equipment
CN112188087B (en) Panoramic video screenshot method and device, storage medium and computer equipment
CN110032390B (en) Method for realizing multi-model co-upgrade package, storage medium and intelligent terminal
CN106204668B (en) Picture decoding method and device
CN113835789A (en) Rendering method, rendering device, electronic equipment and computer storage medium
CN107092601B (en) Resource file construction method, resource file application method and device
CN106020729A (en) Clearing method and device for multi-media data of mobile terminal
CN113822978B (en) Electronic map rendering method and device
CN106445595B (en) Method and device for constructing Application object of plug-in
CN112330816B (en) AR identification processing method and device and electronic device
CN116974732A (en) Memory processing method, device, terminal equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant