CN106598679A - Method and device for loading picture resources - Google Patents
Method and device for loading picture resources Download PDFInfo
- Publication number
- CN106598679A CN106598679A CN201611189784.2A CN201611189784A CN106598679A CN 106598679 A CN106598679 A CN 106598679A CN 201611189784 A CN201611189784 A CN 201611189784A CN 106598679 A CN106598679 A CN 106598679A
- Authority
- CN
- China
- Prior art keywords
- resource
- picture
- loading
- image content
- 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.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring 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. The method comprises the steps that a loading program of picture background settings and a loading program of picture content display are encapsulated into a picture resource loading class, and a resource management interface is encapsulated for the picture resource loading class; in this way, two loading programs are included under the resource management interface, namely the loading program of picture background settings and the loading program of picture content display; when picture resource loading is needed, no matter for loading picture background settings or for loading picture content display, a business layer can call the corresponding picture resource loading class through the resource management interface to load a corresponding picture background and the picture content display concurrently, therefore, the resource loading process is optimized, and the resource loading cost is lowered.
Description
Technical field
The invention belongs to resource loading technique field, more particularly to a kind of method and device of the resource that Loads Image.
Background technology
With the continuous development of electronic product, intelligent terminal substantially has become the indispensable electronic product of staff.At present
Main flow terminal (such as mobile phone, panel computer etc.) operating system include:Android system and IOS systems.
Picture loading function is the basic function that terminal operating system needs to have, in prior art, for Android systems
The version united before 3.0 versions, when loading to picture resource, generally using the resource loading method of system default to figure
Piece is loaded, but the resource loading method of system default cannot be carried out to the loading of picture resource when resource is Loaded Image
Unified management, causes the process of resource loading loaded down with trivial details, and increased the cost of resource loading.
The content of the invention
For the problem that prior art is present, the method and dress of a kind of resource that Loads Image are embodiments provided
Put, for solving the version in prior art below 3.0 version of android system, when resource is Loaded Image, it is impossible to picture
The technical problem is managed collectively by the loading of resource.
The invention discloses a kind of method of the resource that Loads Image, methods described includes:
The loading procedure that the loading procedure and image content that picture background is arranged shows is encapsulated to picture resource loading classes
In;
One resource management's interface of class wrapper is loaded for the picture resource;
By the corresponding picture resource loading classes of resource management's interface interchange, corresponding picture background and picture are loaded
Content shows.
In such scheme, after loading to the picture resource, methods described also includes:To generate in loading procedure
Bitmap pixels data be stored in the bitmap set for pre-building.
In such scheme, after the bitmap pixels data generated in loading procedure are stored in the bitmap set, the side
Method also includes:
According to default recovery opportunity by resource management's interface interchange picture resource reclaimer, reclaim useless
Picture resource.
In such scheme, the recovery opportunity be specially interface on picture be deleted when.
In such scheme, when the picture resource is loaded as the loading of picture background setting, loading method is specifically included:
When it is determined that the picture background does not load out-of-date, the view dimensions that acquisition needs show, according to the view dimensions
Judge whether the picture background needs compression;
When it is determined that the picture background needs compression, the picture background is compressed according to the first compression factor;
First bitmap pixels data of the picture background are generated according to the picture background after compression;
When it is determined that the picture background is normal picture, according to the first bitmap pair of the first bitmap pixels data genaration
As;
First bitmap object is assigned to the view for needing to show picture background.
In such scheme, when it is determined that the picture background need not compress, methods described also includes:According to current figure
First bitmap pixels data of picture background described in piece Background generation.
In such scheme, in loading procedure, methods described also includes:Low memory exception is caught, when capturing exception
When, abandon loading current picture background resource.
In such scheme, when it is determined that the picture background was loaded, methods described also includes:Call from bitmap set
First bitmap pixels data of the picture background.
In such scheme, when it is determined that the picture background is nine figure of point, methods described also includes:
Delete the first bitmap pixels data for generating;
Picture background resource is searched and is parsed using resource ID, generates the second bitmap object;
By the second bitmap object value to the view for needing display picture background.
In such scheme, before the resource that Loads Image, methods described also includes:
Resource type is judged according to resource ID;
When it is determined that the resource type is picture resource, by the corresponding picture resource of resource management's interface interchange
Loading classes, load corresponding picture resource.
In such scheme, the resource type includes:Picture resource, colour resource and XML resources.
In such scheme, when it is determined that the resource type is colour resource and XML file resource, methods described is also wrapped
Include:
Corresponding resource is searched and is parsed using the resource ID, generates corresponding bitmap object;
Corresponding bitmap object is assigned to the view for needing to show the picture background.
In such scheme, when the picture resource is loaded as the loading that image content shows, loading method is specifically included:
When it is determined that the image content shows does not load out-of-date, the view dimensions that acquisition needs show, according to the view
Size judges that the image content displays whether to need compression;
When it is determined that the image content is shown when needing compression, compressing the image content according to the second compression factor and show
Show;
The the second bit image prime number evidence for generating that the image content shows is shown according to the image content after compression;
When it is determined that the image content show be not point nine figure when, according to the second bit image prime number according to generate the 3rd
Figure object;
3rd bitmap object is assigned to the view for needing to show that image content shows.
Invention additionally discloses a kind of device of the resource that Loads Image, described device includes:
First encapsulation unit, for the loading procedure encapsulation that the loading procedure that arranges picture background and image content show
Into picture resource loading classes;
Second encapsulation unit, for loading one resource management's interface of class wrapper for the picture resource;
Call unit, for by the corresponding picture resource loading classes of resource management's interface interchange, loading is corresponding
Picture background and image content show.
In such scheme, described device also includes storage element, after loading to the picture resource, the storage
Unit is used for:The bitmap pixels data generated in loading procedure are stored in the bitmap set for pre-building.
In such scheme, the call unit is additionally operable to adjust by resource management's interface according to default recovery opportunity
Picture resource reclaimer is used, useless picture resource is reclaimed.
In such scheme, the recovery opportunity be specially interface on picture be deleted when.
In such scheme, when the picture resource is loaded as the loading of picture background setting, first encapsulation unit
Including:
First determination subelement, do not load out-of-date, view chi that acquisition needs show when the picture background for determining
It is very little, judge whether the picture background needs compression according to the view dimensions;When it is determined that when the picture background needs compression
When, the picture background is compressed according to the first compression factor;
First generates subelement, for the first bitmap pixels of the picture background are generated according to the picture background after compression
Data;
Second determination subelement, for determine the picture background be normal picture when, according to first bitmap pixels
The first bitmap object of data genaration;
First assignment subelement, for first bitmap object to be assigned to need the view for showing picture background.
In such scheme, when first determination subelement determines that the picture background need not compress, described first
Generate subelement to be additionally operable to:First bitmap pixels data of the picture background are generated according to current picture background.
In such scheme, first encapsulation unit also includes:First catches subelement, for catching in loading procedure
Low memory exception, when capturing abnormal, abandons loading the picture background resource.
In such scheme, first encapsulation unit also includes:First calls subelement, when first determination subelement
Determine that the picture background has been loaded out-of-date, described first calls subelement for the picture background is called from bitmap set
The first bitmap pixels data.
In such scheme, first encapsulation unit also includes:First deletes subelement;When second determination subelement
The picture background is determined to put during nine figure,
Described first deletes subelement is used to delete the first bitmap pixels data for generating;
The first generation subelement is additionally operable to picture background resource is searched and parsed using resource ID, generates the second bitmap
Object;
The first assignment subelement is additionally operable to the second bitmap object value to needing to show that picture background is regarded
Figure.
In such scheme, before the resource that Loads Image, first determination subelement is additionally operable to be judged according to resource ID
Resource type;
When it is determined that when the resource type is picture resource, the call unit is used for by resource management's interface
Corresponding picture resource loading classes are called, corresponding picture resource is loaded.
In such scheme, the resource type includes:Picture resource, colour resource and XML resources.
In such scheme, first encapsulation unit also includes:Second generates subelement;Wherein, when described first determines
Subelement determines that when the resource type be colour resource and during XML file resource,
The second generation subelement is used to corresponding resource to be searched and parsed using the resource ID, generates corresponding position
Figure object;
The first assignment subelement is additionally operable to be assigned to need the view of display picture background by corresponding bitmap object.
In such scheme, when the picture resource is loaded as the loading that image content shows, first encapsulation unit
Also include:
3rd determination subelement, does not load out-of-date, the view that acquisition needs show for determining that the image content shows
According to the view dimensions, size, judges that the image content displays whether to need compression;Need when the image content shows
During compression, the image content is compressed according to the second compression factor and is shown;
3rd generates subelement, for generate that the image content shows second is shown according to the image content after compression
Bitmap pixels data;
4th determination subelement, for determining when the image content is shown as normal picture, according to the second
Figure pixel data generates the 3rd bitmap object;
Second assignment subelement, for being assigned to need to show that what image content showed regards by the 3rd bitmap object
Figure.
The invention provides a kind of method and device of the resource that Loads Image, methods described includes:Picture background is arranged
Loading procedure and the loading procedure that shows of image content encapsulate into picture resource loading classes, and load for the picture resource
One resource management's interface of class wrapper;So, two kinds of loading procedures are just included under resource management's interface:What picture background was arranged
The loading procedure that loading procedure and image content show;When needing to Load Image resource, the background that either Loads Image is arranged
Still the content that Loads Image shows that operation layer can be by the corresponding picture resource loading of resource management's interface interchange
Class, loads corresponding picture background in the lump and the image content shows, so as to optimize resource loading procedure, reduces resource
The cost of loading.
Description of the drawings
Fig. 1 is the method flow schematic diagram of the resource that Loads Image provided in an embodiment of the present invention;
Fig. 2 is the method flow schematic diagram of the background that Loads Image provided in an embodiment of the present invention;
Fig. 3 is the method flow schematic diagram that the content that Loads Image provided in an embodiment of the present invention shows;
Fig. 4 is the apparatus structure schematic diagram of the resource that Loads Image provided in an embodiment of the present invention;
Fig. 5 is the structural representation of the first encapsulation unit provided in an embodiment of the present invention;
Fig. 6 is the another structural representation of the first encapsulation unit provided in an embodiment of the present invention.
Specific embodiment
In order that the application the technical staff in the technical field is more clearly understood that the application, below with reference to accompanying drawings
The exemplary embodiment of the disclosure is more fully described.Although the exemplary embodiment of the disclosure is shown in accompanying drawing, but should
Work as understanding, may be realized in various forms the disclosure and should not be limited by embodiments set forth here.On the contrary, there is provided these realities
Apply example to be able to be best understood from the disclosure, and can be by the scope of the present disclosure complete skill for conveying to this area
Art personnel.
Embodiment one
The present embodiment provides a kind of method of the resource that Loads Image, as shown in figure 1, methods described includes:
S101, the loading procedure that the loading procedure and image content that picture background is arranged shows are encapsulated to picture resource and are added
Carry apoplexy due to endogenous wind.
In this step, the picture resource generally comprises picture background setting and image content shows, in the money that Loads Image
During source, need to background arrange and image content shows and loads, therefore by picture background setting loading procedure and picture
The loading procedure that content shows is encapsulated into picture resource loading classes Decode DrawableHelper, convenient unified loading pipe
Reason.
The loading procedure that the loading procedure and image content that picture background is arranged shows is encapsulated to picture resource loading classes
After in Decode DrawableHelper, also need to set up bitmap set mLeakBitmaps, generating in loading procedure
Bitmap pixels data Bitmap are stored in the bitmap set mLeakBitmaps for pre-building.
Here, the loading procedure that the loading procedure and image content for picture background being arranged shows is encapsulated to picture resource and is added
Carry class Decode DrawableHelper realizes that program is as follows:
DecodeDrawableHelper.loadBackground
DecodeDrawableHelper.loadImage
The Background refers to picture background, and the Image refers to that image content shows.
Specifically, it is when the picture resource is loaded as the loading of picture background setting, referring to Fig. 2, described
The corresponding loading methods of DecodeDrawableHelper.loadBackground are:
S201, receives resource, judges whether resource type is picture resource according to resource ID.
Here, the different resource ID of different resource type correspondences, after resource is received, determines resource according to resource ID
For picture background resource when, execution step S202;When it is determined that resource is colour resource and XML resources, execution step S203.Its
In, the resource type includes picture resource, colour resource and XML resources;The picture resource can include:Normal picture and
Nine figures of point;The colour resource includes the colour type such as such as RGB8, RGB4.
S202, judges whether picture background loaded, when it is determined that the picture background does not load out-of-date, execution step
S204.When the picture background has loaded out-of-date, execution step S205.
S203, when it is determined that resource is colour resource and XML resources, according to the colour resource and the corresponding resources of XML
ID, generates corresponding bitmap object;Corresponding bitmap object is assigned to need the view of display background.
Specifically, corresponding bitmap object is obtained by Resources.getDrawable (resId) mode
Drawable, and the bitmap object Drawable is assigned to into view View so that view View can show corresponding money
Source.Wherein, the resId acute pyogenic infection of finger tip resource ID.
Here, before the bitmap object Drawable being assigned to view View, methods described also includes:
Judge whether the SDK_INT in system is more than 16, when it is determined that the SDK_INT is more than or equal to 16, View is adjusted
Bitmap object Drawable is obtained with setBackground (drawable) method, is carried on the back using bitmap object Drawable assignment
Scape, so as to show corresponding resource;When it is determined that the SDK_INT is less than 16, View is called
SetBackgroundDrawable) (drawable) method obtains bitmap object Drawable, using bitmap object Drawable
Assignment background, so as to show corresponding resource.It should be noted that the background of indication refers to display colour resource and XML herein
The display background of resource is different from picture background.
S204, obtaining needs the size of the view View sizes and picture background for showing, is judged according to the view dimensions
Whether the picture background needs compression;When the picture background needs compression, execution step 206;When the picture background
When need not compress, execution step 207.
Here, the size for obtaining picture background in this step is that, in order to reduce EMS memory occupation, concrete implementation mode is:
Whether only the value for arranging acquisition border inJustDecodeBounds is true, when true is set to, in the background that Loads Image
During, the length information of picture background can be only got, without going really to parse picture background.Read picture
After the size of background, the value of inJustDecodeBounds is set to into false.
S205, when it is determined that the picture background has loaded out-of-date, calling from the bitmap set mLeakBitmaps
First bitmap pixels data Bitmap of the picture background.Wherein, in order to reduce the first bitmap pixels data Bitmap
Committed memory, pixel in the first bitmap pixels data Bitmap is arranged in the present embodiment and takes 2 bytes, for example,
The load format of the first bitmap pixels data Bitmap can be set to Bitmap.Config.RGB_565, described
The byte that Bitmap.Config.RGB_565 takes is 2.
S206, compresses the picture background according to the first compression factor, after picture background is compressed, according to the figure after compression
First bitmap pixels data Bitmap of picture background described in piece Background generation;Wherein, first compression factor is according to figure
What piece background size and view dimensions were calculated.
S207, generates the first bitmap pixels data Bitmap of the picture background according to current picture background.
S208, after the first bitmap pixels data Bitmap of picture background are generated, by the first bit image prime number
Cache into bitmap set mLeakBitmaps according to Bitmap, and judge whether the picture background is nine figures of point, as determined institute
State picture background for normal picture when, execution step S209;When the picture as described in determining is nine figure of point, execution step S210.
S209, when it is determined that the picture background is normal picture, according to the first bitmap pixels data genaration first
Bitmap object Drawable;The first bitmap object Drawable is assigned to the view View for needing to show picture background,
So that view View can show picture background.
S210, when it is determined that the picture background is nine figure of point, deletes the first bitmap pixels data for generating
Bitmap;Picture background resource is searched and is parsed using resource ID, generates the second bitmap object Drawable;By the second
Figure object Drawable is assigned to the view View for needing to show picture background.Here, because nine figures of point are that android system is special
The picture/mb-type of support, if nine figures of point, can be according to the transverse and longitudinal iteration region for pre-setting in picture when drawing
Filling duplicate contents.Here, if directly generating the first bitmap object Drawable according to the first bitmap pixels data Bitmap
Mode obtain the first bitmap object Drawable, then can override the attribute of a little nine figures.So when picture background is nine figures of point
When, then need to delete the first bitmap pixels data Bitmap for generating.
In loading procedure, in order to further reduce the cost of resource loading, can be added in units of resource loading classes
Catch of exception, by Try, Catch parcels catch low memory (OOM, Out Of Memorty) exception, when occurring abnormal,
Abandon loading current picture background resource, to avoid causing system application crashes because of low memory.
So far, the loading procedure that the picture background is arranged is completed.
Correspondingly, it is when the picture resource is loaded as the loading that image content shows, referring to Fig. 3, described
The corresponding loading methods of DecodeDrawableHelper.loadImage are:
S301, receives resource, judges resource type according to resource ID.
Here, the different resource ID of different resource type correspondences, after resource is received, determines resource according to resource ID
When showing resource for image content, execution step S302;When it is determined that resource is colour resource and XML resources, execution step
S303.Wherein, the resource type includes picture resource, colour resource and XML resources;The picture resource can include:It is general
Nine figures of logical picture and point;The colour resource includes the colour type such as such as RGB8, RGB4.
S302, judges that image content displays whether to load, when it is determined that the image content shows does not load out-of-date, execution
Step S304.Load out-of-date when the image content shows, execution step S305.
S303, when it is determined that resource is colour resource and XML resources, according to the colour resource and the corresponding resources of XML
ID generates corresponding bitmap object.
Specifically, corresponding bitmap object is obtained by Resources.getDrawable (resId) mode
Drawable, by ImageView.setImageDrawable methods by regarding that bitmap object is assigned to need content to show
Figure so that view View can show corresponding resource.Wherein, the resId acute pyogenic infection of finger tip resource ID.
S304, obtains the size for needing the view View sizes and image content of display to show, according to the view dimensions
Judge that the image content displays whether to need compression;When the image content shows needs compression, execution step 306;When
The image content shown when need not compress, execution step 307.
Here, the size that acquisition image content shows in this step is to reduce EMS memory occupation, concrete implementation side
Formula is:It is true to arrange and whether only obtain border inJustDecodeBounds, when true is set to, in the background that Loads Image
During, the length information that image content shows can be got only, is shown without going really to parse image content.Read
After getting the size that image content shows, then inJustDecodeBounds is set to into false.
S305, when it is determined that the image content show loaded it is out-of-date, from the bitmap set mLeakBitmaps
The second bit image prime number that the image content shows is called according to Bitmap.Wherein, in order to reduce the second bit image prime number
According to the committed memory of Bitmap, the second bit image prime number is arranged according to a pixel in Bitmap in the present embodiment and take 2 words
Section, for example, the second bit image prime number can be Bitmap.Config.RGB_565 according to the load format of Bitmap, described
The byte that Bitmap.Config.RGB_565 takes is 2.
S306, compresses the picture background according to the second compression factor, and image content is shown after compression, after compression
Image content show and generate the second bit image prime number that the image content shows according to Bitmap;Wherein, second compression
Ratio is calculated according to image content display size and view dimensions.
S307, shows the second bit image prime number evidence for generating that the image content shows according to current image content
Bitmap。
S308, after the second bit image prime number that image content shows is according to Bitmap generations, by second bit image
Prime number is cached into bitmap set according to Bitmap, and judges that the image content is displayed whether to put nine figures, is schemed as described in determination
When piece content is shown as normal picture, execution step S309;When the image content as described in determining is shown as a little nine figure, execution step
S310。
S309, when it is determined that the image content is shown as normal picture, according to the second bit image prime number evidence
Bitmap generates the 3rd bitmap object Drawable;The 3rd bitmap object Drawable is assigned to need to show in picture
Hold the view View for showing, so that view View can show that image content shows.
S310, when it is determined that the image content is shown as a little nine figure, deletes the second bit image prime number evidence for generating
Bitmap;Image content is searched and is parsed using resource ID and shows resource, generate the 4th bitmap object;By the 4th bitmap pair
As Drawable is assigned to need the view View for showing that image content shows.Here, because nine figures of point are that android system is special
The picture/mb-type of support, if nine figures of point, can be according to the transverse and longitudinal iteration region for pre-setting in picture when drawing
Filling duplicate contents.Here, if directly generating threeth bitmap object Drawable according to Bitmap according to the second bit image prime number
Mode obtain the 3rd bitmap object Drawable, then can override the attribute of a little nine figures.So being a little when image content shows
During nine figures, then need to delete the second bit image prime number for generating according to Bitmap.
In loading procedure, in order to further reduce the cost of resource loading, can be added in units of resource loading classes
Catch of exception, by Try, it is abnormal that Catch parcels catch low memory (OOM, Out Of Memorty), when capturing exception
When, abandon loading current picture resource, to avoid causing system application crashes because of low memory.
So far, the loading procedure that the image content shows is completed.
When it should be noted that the background that either Loads Image in the present embodiment still Loads Image, content shows, in money
In the loading classes of source, same resource is only loaded once, effectively reduces the repetition loading of resource, it is to avoid because resource repetition is loaded out
The phenomenon that existing internal memory shake causes loading procedure unstable.
Further, in order to picture resource useless in bitmap set mLeakBitmaps can be reclaimed, realize internal memory pipe
That what is managed is controllable, it is to avoid because low memory causes application crashes, the present embodiment is in the loading procedure and picture for arranging picture background
After the loading procedure that content shows is encapsulated into picture resource loading classes, also program releaseSrc of picture resource will be reclaimed
() is encapsulated into the picture resource loading classes, and the journey that the program of picture resource recovery is loaded with the picture resource
Sequence shares resource management's interface, and program releaseSrc () of the recovery picture resource is implemented as follows:
Here, when recovery opportunity of default picture resource is triggered to, then resource management's interface interchange can be passed through
The circulation of resource reclaim program performs recycle, reclaims sets of bit-maps and closes useless to the first bitmap pixels in mLeakBitmaps
Data Bitmap and the first bitmap pixels data Bitmap.Wherein, the picture on the recovery opportunity specially interface is deleted
When.
S102, is picture resource loading one resource management's interface of class wrapper.
The loading procedure shown when the loading procedure, image content that arrange picture background and the reclaimer of picture resource
After encapsulating into picture resource loading classes, also need to load one resource management's interface of class wrapper for the picture resource
IDecodeDrawableHelper, when needing to load picture resource or reclaim picture resource, need to only pass through
Resource management's interface can call the picture resource loading procedure in resource loading classes to load picture resource, or logical
Cross resource management's interface interchange picture resource reclaimer to reclaim picture resource.Thus can be by same resource
Management interface realizes that picture background is arranged, image content shows and picture resource is reclaimed, so as to realizing picture resource loading and returning
The unified management of receipts.
Specifically, the encapsulation process of resource management's interface IDecodeDrawableHelper is as follows:
As can be seen that under resource management's interface IDecodeDrawableHelper, comprising two methods:First
It is getHelper, refers to the resource loading method under the loading classes for obtaining encapsulation;Second is releaseSrc, refers to Resource recovery
Method.
S103, by the corresponding picture resource loading classes of resource management's interface interchange, loads corresponding picture background
And the image content shows.
In this step, when the loading procedure that the loading procedure and image content that arrange picture background show is encapsulated to picture
In resource loading classes;And will be picture resource loading classes corresponding resource management interface IDecodeDrawableHelper packaged
Afterwards;Can excessively described resource management's interface IDecodeDrawableHelper call corresponding picture resource loading classes, load
Corresponding picture background and image content show that specific loading method can be found in step 201~210 and step 201~210;
Or call picture resource to return by resource management's interface IDecodeDrawableHelper according to default recovery opportunity
Receipts program, reclaims useless picture resource, and specific Resource recovery method can be found in step S101.
In actual applications, the picture resource loading method and picture resource recovery method described in step S101 can be fitted
For in arbitrary View, in ViewGroup and in base class BaseActivity, with the base class of the Activity in certain browser
As a example by BaseActivity, the method that the method and picture resource of picture resource loading are reclaimed is implemented as follows:
The method for obtaining the picture resource loading under the picture resource loading classes of encapsulation:
In loading procedure, when interface images are deleted, i.e., resource reclaim side is called in Activity onDestroy
Method releaseSrc is reclaimed to picture resource, and the program realization of invoked procedure is as follows:
So in BaseActivity, and it is inherited from the class of BaseActivity, when the resource that Loads Image
Only need to load by calling getHelper () .loadBackground to arrange picture background, or by calling
The method of getHelper.loadImage shows to image content and loads;When reclaiming picture resource, as long as being triggered to
Recovery opportunity can call releaseSrc to reclaim useless picture resource.
Embodiment two
Corresponding to embodiment one, the present embodiment also provides a kind of device of the resource that Loads Image, as shown in figure 4, the dress
Put including:First encapsulation unit 41, the second encapsulation unit 42, call unit 43 and storage element 44 5;Wherein,
The loading journey that first encapsulation unit 41 is shown for the loading procedure that arranges picture background and image content
Sequence is encapsulated into picture resource loading classes;Wherein, the picture resource generally comprises picture background setting and image content shows,
When resource is Loaded Image, need to arrange background and image content shows and loads, therefore adding picture background setting
The loading procedure that load program and image content show is encapsulated into picture resource loading classes Decode DrawableHelper, side
Just unified loading management.
The loading procedure envelope that the loading procedure and image content that picture background is arranged by first encapsulation unit 41 shows
After being filled in picture resource loading classes Decode DrawableHelper, also need to set up bitmap set mLeakBitmaps, it is described
Storage element 44 is can be stored in the bitmap set for pre-building by bitmap pixels data Bitmap generated in loading procedure
In mLeakBitmaps.
Here, the loading journey that the loading procedure and image content that picture background is arranged by first encapsulation unit 41 shows
To picture resource loading classes Decode DrawableHelper, sequence is encapsulated realizes that program is as follows:
DecodeDrawableHelper.loadBackground
DecodeDrawableHelper.loadImage
The Background refers to picture background, and the Image refers to that image content shows.
Specifically, referring to Fig. 5, first encapsulation unit 41 includes:First determination subelement 51, first call subelement
52nd, first subelement 53, the second determination subelement 54, first assignment subelement the 55, first deletion life of subelement 56, second are generated
Subelement 58 is caught into subelement 57 and first;Wherein,
When the picture resource is loaded as the loading of picture background setting, first determination subelement 51 is used to receive
Resource, judges resource type according to resource ID.Here, because of the resource ID that different resource type correspondences is different, therefore can be with root
Resource type is judged according to resource ID.Wherein, the resource type includes picture resource, colour resource and XML resources;The figure
Piece resource can include:Nine figures of normal picture and point;The colour resource includes the colour type such as such as RGB8, RGB4.
When it is picture background resource that first determination subelement 51 determines resource, also need to judge whether picture background adds
Carried, when it is determined that the picture background do not load it is out-of-date, obtain need show view View sizes and picture background size,
Judge whether the picture background needs compression according to the view dimensions.When it is determined that the picture background needs compression, root
The picture background is compressed according to the first compression factor.Here, the first determination subelement 51 obtain picture background size be in order to
EMS memory occupation is reduced, concrete implementation mode is:First determination subelement 51 is arranged and whether only obtains border
The value of inJustDecodeBounds is true, when true is set to, during the background that Loads Image, can only be got
The length information of picture background, without going really to parse picture background.When the first determination subelement 51 reads picture
After the size of background, inJustDecodeBounds is set to into false.
Further, when first determination subelement 51, to determine that the picture background has been carried out-of-date, and described first calls
Subelement 52 is for calling the first bitmap pixels data of the picture background from the bitmap set mLeakBitmaps
Bitmap.Wherein, in order to reduce the committed memory of the first bitmap pixels data Bitmap, by the first bitmap in the present embodiment
In pixel data Bitmap, a pixel is arranged and takes 2 bytes, for example, the load format of the first bitmap pixels data Bitmap
Can be Bitmap.Config.RGB_565, the byte that the Bitmap.Config.RGB_565 takes is 2.
When first determination subelement 51 determines that the picture background need not compress, described first generates subelement
53 are additionally operable to the first bitmap pixels data Bitmap of the picture background are generated according to current picture background.
When the described first generation subelement 53 generates the first bit image of the picture background according to current picture background
After prime number is according to Bitmap, the storage element 44 caches the first bitmap pixels data Bitmap to bitmap set
In mLeakBitmaps.
When the described first generation subelement 53 generates the first bit image of the picture background according to current picture background
After prime number is according to Bitmap, second determination subelement 54 is used to judge whether the picture background is nine figures of point, as determined institute
State picture background for normal picture when, be additionally operable to according to the first bitmap pixels data Bitmap generate the first bitmap object
First bitmap object Drawable then is assigned to need to show picture background by Drawable, the first assignment subelement 55
View View, so that view View can show picture background.
When it is nine figure of point that second determination subelement 54 determines the picture background, described first deletes subelement 56
For deleting the first bitmap pixels data Bitmap for generating;The first generation subelement 53 is additionally operable to utilize resource ID
Picture background resource is searched and parsed, the second bitmap object is generated;So be additionally operable to will be described for the first assignment subelement 55
Second bitmap object value is to the view View for needing display picture background.Here, because nine figures of point are special of android systems
The picture/mb-type held, if nine figures of point, can fill out according to the transverse and longitudinal iteration region for pre-setting in picture when drawing
Fill duplicate contents.Here, if directly turning the side of the first bitmap object Drawable according to the first bitmap pixels data Bitmap
Formula obtains the first bitmap object Drawable, then can override the attribute of a little nine figures.So when picture background is nine figure of point, then
Need to delete the first bitmap pixels data Bitmap for generating.
Further, when it is colour resource and XML resources that first determination subelement 51 determines resource, described second
Generate subelement 57 to be additionally operable to, according to the colour resource and the corresponding resource IDs of XML, generate corresponding bitmap object;Described
One assignment subelement 55 is additionally operable to be assigned to need the view of display background by corresponding bitmap object.
Specifically, when first determination subelement 51 is when it is determined that resource is colour resource and XML resources, described second
Generate subelement 57 and corresponding bitmap object Drawable, institute are obtained by Resources.getDrawable (resId) mode
State the first assignment subelement 55 and the bitmap object Drawable is assigned to into view View so that view View can show phase
The resource answered.Wherein, the resId acute pyogenic infection of finger tip resource ID.
Here, before the bitmap object Drawable is assigned to view View by the first assignment subelement 55, described
One determination subelement 51 is additionally operable to:Judge whether the SDK_INT in system is more than 16, when it is determined that the SDK_INT is more than or waits
When 16, View calls setBackground (drawable) method to obtain bitmap object Drawable, using bitmap object
Drawable assignment backgrounds, so as to show corresponding resource;When it is determined that the SDK_INT is less than 16, View is called
SetBackgroundDrawable) (drawable) method obtains bitmap object Drawable, using bitmap object Drawable
Assignment background, so as to show corresponding resource.It should be noted that the background of indication refers to display colour resource and XML herein
The display background of resource is different from picture background.
In addition, in loading procedure, in order to further reduce the cost of resource loading, first encapsulation unit 41 is also wrapped
Include:First catches subelement 58, and first catch subelement 58 to be used for resource loading classes being unit, adds catch of exception, passes through
Try, Catch parcel catches low memory (OOM, Out Of Memorty) exception, when occurring abnormal, abandons loading current
Picture background resource, to avoid causing system application crashes because of low memory.
Correspondingly, when the picture resource is loaded as the loading that image content shows, referring to Fig. 6, first encapsulation
Unit 41 also includes:3rd determination subelement 61, second call subelement the 62, the 3rd to generate the determination son list of subelement the 63, the 4th
The 64, second assignment subelement of unit 65, second is deleted subelement the 66, the 4th and generates subelement 67 and the second seizure subelement 68;Its
In,
3rd determination subelement 61 is used to receive resource, judges resource type according to resource ID.Here, different money
The different resource ID of Source Type correspondence, therefore resource type can be judged according to resource ID.
After resource is received, the 3rd determination subelement 61 determines resource according to resource ID and shows money for image content
During source, judge that image content displays whether to load, when it is determined that the image content show do not load it is out-of-date;Acquisition needs to show
View View sizes and the size that shows of image content, judge that the image content displays whether need according to the view dimensions
Compress;When it is determined that the image content is shown when needing compression, compressing the image content according to the second compression factor and show,
Image content is shown after compression, the second bit image for generating that the image content shows is shown according to the image content after compression
Prime number is according to Bitmap;Wherein, second compression factor is calculated according to image content display size and view dimensions.
Here, the size that the acquisition of the 3rd determination subelement 61 image content shows is the concrete implementation in order to reduce EMS memory occupation
Mode is:Whether only the value for arranging acquisition border inJustDecodeBounds is true, when true is set to, in loading figure
During piece background, the length information that image content shows can be got only, without going really to parse image content
Show.After reading the size that image content shows, then the value of inJustDecodeBounds is set to into false.
Load out-of-date when the 3rd determination subelement 61 determines that the image content shows, described second calls sub- list
Unit 62 is for from the bitmap set mLeakBitmaps, call the image content to show the second bit image prime number evidence
Bitmap.Wherein, in order to reduce committed memory of the second bit image prime number according to Bitmap, by the second bitmap in the present embodiment
In pixel data Bitmap, a pixel is arranged and takes 2 bytes, for example, load format of the second bit image prime number according to Bitmap
Can be Bitmap.Config.RGB_565, the byte that the Bitmap.Config.RGB_565 takes is 2.
When the 3rd determination subelement 61 determine the image content show need not compress when, it is described 3rd generate son
Unit 63 shows the second bit image prime number for generating the picture background according to Bitmap according to current image content.
When the described 3rd generation subelement 63 shows the second bit image that image content shows according to current image content
After prime number is according to Bitmap generations, the second bit image prime number is cached into bitmap set according to Bitmap, the described 4th is true
Stator unit 64 is used to judge that the image content is displayed whether to put nine figures that the image content as described in determination to be shown as common figure
During piece, it is described 3rd generate subelement 63 for according to the second bit image prime number according to generate the 3rd bitmap object
Drawable;The 3rd bitmap object Drawable is assigned to need to show image content by the second assignment subelement 65
The view View of display, so that view View can show that image content shows.
When the 4th determination subelement 64 determines that the image content is shown as a little nine figure, described second deletes son list
Unit 66 is used to delete the second bit image prime number for generating according to Bitmap;The 3rd generation subelement 63 is additionally operable to using money
Source ID is searched and is parsed image content and shows resource, generates the 4th bitmap object Drawable;The second assignment subelement 65
It is additionally operable to be assigned to need show the view View that image content shows by the 4th bitmap object.Here, because putting nine figures it is
The picture/mb-type of special support, if nine figures of point, can be according to the transverse and longitudinal iteration for pre-setting in picture when drawing
Area filling duplicate contents.Here, if directly generating threeth bitmap object according to Bitmap according to the second bit image prime number
The mode of Drawable obtains the 3rd bitmap object Drawable, then can override the attribute of a little nine figures.So working as image content
When display is nine figure of point, then need to delete the second bit image prime number for generating according to Bitmap.
Further, when it is colour resource and XML resources that the 3rd determination subelement 61 determines resource, the described 4th
Generate subelement 67 to be additionally operable to generate corresponding bitmap object according to the colour resource and the corresponding resource IDs of XML.Described
Two assignment subelements 65 are additionally operable to be assigned to need display to show the view that image content shows by corresponding bitmap object.
Specifically, when it is colour resource and XML resources that the 3rd determination subelement 61 determines resource, the 4th life
Corresponding bitmap object Drawable is obtained by Resources.getDrawable (resId) mode into subelement 67, it is described
Bitmap object is assigned to need content to show by the second assignment subelement 65 by ImageView.setImageDrawable methods
The view for showing so that view View can show corresponding resource.Wherein, the resId acute pyogenic infection of finger tip resource ID.
In addition, in loading procedure, in order to further reduce the cost of resource loading, first encapsulation unit 41 is also wrapped
Include:Second catches subelement 68, and second catch subelement 68 to be used for resource loading classes being unit, adds catch of exception, passes through
Try, Catch parcel catches low memory OOM exceptions, when occurring abnormal, abandons loading current picture resource, with avoid because
Low memory causes system application crashes.
When it should be noted that the background that either Loads Image in the present embodiment still Loads Image, content shows, in money
In the loading classes of source, same resource is only loaded once, effectively reduces the repetition loading of resource, it is to avoid because resource repetition is loaded out
The phenomenon that existing internal memory shake causes loading procedure unstable.
Further, in order to picture resource useless in bitmap set mLeakBitmaps can be reclaimed, realize internal memory pipe
That what is managed is controllable, it is to avoid because low memory causes application crashes, the loading journey that picture background is arranged by first encapsulation unit 41
After the loading procedure that sequence and image content show is encapsulated into picture resource loading classes, the program by picture resource is reclaimed is additionally operable to
ReleaseSrc () is encapsulated into the picture resource loading classes, and the program that the picture resource is reclaimed is provided with the picture
One resource management's interface of program sharing of source loading, program releaseSrc () of the recovery picture resource implement as
Under:
Here, when recovery opportunity of default picture resource is triggered to, then execution recycle can be circulated, position is reclaimed
It is useless to the first bitmap pixels data Bitmap and the first bitmap pixels data Bitmap in set of graphs mLeakBitmaps.Its
In, the recovery opportunity be specially interface on picture be deleted when.
Further, the loading procedure that arranges picture background when first encapsulation unit 41, image content show
After the reclaimer of loading procedure and picture resource is encapsulated into picture resource loading classes, second encapsulation unit 42 be used for be
The picture resource loads one resource management's interface of class wrapper.
Specifically, when the loading procedure, image content that arrange picture background when first encapsulation unit 41 show
After the reclaimer of loading procedure and picture resource is encapsulated into picture resource loading classes, also need as the picture resource loading classes
A resource management interface IDecodeDrawableHelper is encapsulated, is needing to load picture resource or to picture resource
When being reclaimed, only the picture resource loading procedure in resource loading classes need to can be called to figure by resource management's interface
Piece resource is loaded, or picture resource is reclaimed by resource management's interface interchange picture resource reclaimer.So
Just can realize that picture background is arranged, image content shows and picture resource is reclaimed by same resource management's interface, so as to
Realize picture resource loading and the unified management reclaimed.
Specifically, the resource management's interface of second encapsulation unit 42 pairs
As can be seen that under resource management's interface IDecodeDrawableHelper, comprising two methods:First
It is getHelper, refers to the resource loading method under the loading classes for obtaining encapsulation;Second is releaseSrc, refers to Resource recovery
Method.
The loading procedure that the loading procedure and image content picture background arranged when first encapsulation unit 41 shows
Encapsulate into picture resource loading classes;Second encapsulation unit 42 is by picture resource loading classes corresponding resource management's interface
After IDecodeDrawableHelper is packaged, the call unit 43 can be by resource management's interface interchange phase
The picture resource loading classes answered, load corresponding picture background and image content shows.Specific loading procedure can be found in above;
Or the call unit 43 also can pass through resource management's interface according to default recovery opportunity
IDecodeDrawableHelper calls picture resource reclaim program, reclaims useless picture resource, specific Resource recovery mistake
Journey also can be found in above.
In actual applications, above described in picture resource loading procedure and picture resource removal process go for
In arbitrary View, in ViewGroup and in base class BaseActivity, with the base class of the Activity in certain browser
As a example by BaseActivity, the process that the process and picture resource of picture resource loading are reclaimed is implemented as follows:
The method for obtaining the picture resource loading under the picture resource loading classes of encapsulation:
In loading procedure, when interface images are deleted, i.e., in Activity onDestroy, the call unit 43
Its recovery method as resource releaseSrc can be called to reclaim picture resource, the program realization of the invoked procedure is as follows:
So in BaseActivity, and it is inherited from the class of BaseActivity, when the resource that Loads Image
Only need to load by calling getHelper () .loadBackground to arrange picture background, or by calling
The method of getHelper.loadImage shows to image content and loads;When reclaiming picture resource, as long as being triggered to
Recovery opportunity can call releaseSrc to reclaim useless picture resource.
By one or more embodiment of the present invention, the invention has the advantages that or advantage:
The invention discloses a kind of method and device of the resource that Loads Image, before the resource that Loads Image, picture is carried on the back
The loading procedure that the loading procedure and image content that scape is arranged shows is encapsulated into picture resource loading classes, and is provided for the picture
Source loads one resource management's interface of class wrapper;So, two kinds of loading procedures are just included under resource management's interface:Picture background
The loading procedure that the loading procedure and image content of setting shows;When needing to Load Image resource, either Load Image the back of the body
Scape arranges the content that still Loads Image and shows that operation layer can pass through the corresponding picture resource of resource management's interface interchange
Loading classes, load corresponding picture background in the lump and the image content shows, so as to optimize resource loading procedure, reduce
The cost of resource loading.Also, in units of resource loading classes, add catch of exception, the exception that can occur to loading procedure
Carry out unifying to catch and processing, reduce further the cost of resource loading.
The background that either Loads Image still Loads Image content when showing, in resource loading classes, same resource is only
Loading once, effectively reduces the repetition loading of resource, it is to avoid cause loading procedure because internal memory shake occurs in resource repetition loading
Unstable phenomenon.In addition, methods described is by pre-building bitmap set, by the bit image prime number of the generation in loading procedure
According to storing into the bitmap set, realize that memory management is controllable, and resource reclaim program also encapsulated into resource loading classes,
And add recovery opportunity in resource reclaim program, when the recovery opportunity is triggered, then can be connect by identical resource management
In mouthful calling resource reclaim program para-position set of graphs, useless picture resource is reclaimed in time, and it is controllable to realize resource reclaim,
The not enough caused OOM of NativeCache are solved the problems, such as fundamentally.And the unified pipe for also achieve resource loading, reclaiming
Reason.
Algorithm and display be not inherently related to any certain computer, virtual system or miscellaneous equipment provided herein.
Various general-purpose systems can also be used together based on teaching in this.As described above, construct required by this kind of system
Structure be obvious.Additionally, the present invention is also not for any certain programmed language.It is understood that, it is possible to use it is various
Programming language realizes the content of invention described herein, and the description done to language-specific above is to disclose this
Bright preferred forms.
In description mentioned herein, a large amount of details are illustrated.It is to be appreciated, however, that the enforcement of the present invention
Example can be put into practice in the case where not having these details.In some instances, known method, structure is not been shown in detail
And technology, so as not to obscure the understanding of this description.
Similarly, it will be appreciated that in order to simplify the disclosure and help understand one or more in each inventive aspect, exist
Above to, in the description of the exemplary embodiment of the present invention, each feature of the present invention is grouped together into single enforcement sometimes
In example, figure or descriptions thereof.However, should the method for the disclosure be construed to reflect following intention:I.e. required guarantor
The more features of feature is expressly recited in each claim by the application claims ratio of shield.More precisely, such as following
Claims it is reflected as, inventive aspect is less than all features of single embodiment disclosed above.Therefore,
Thus the claims for following specific embodiment are expressly incorporated in the specific embodiment, wherein each claim itself
All as the separate embodiments of the present invention.
Those skilled in the art are appreciated that can be carried out adaptively to the module in the equipment in embodiment
Change and they are arranged in one or more different from embodiment equipment.Can be the module or list in embodiment
Unit or component are combined into a module or unit or component, and can be divided in addition multiple submodule or subelement or
Sub-component.In addition at least some in such feature and/or process or unit is excluded each other, can adopt any
Combine to all features disclosed in this specification (including adjoint claim, summary and accompanying drawing) and so disclosed
Where all processes or unit of method or equipment are combined.Unless expressly stated otherwise, this specification (includes adjoint power
Profit is required, summary and accompanying drawing) disclosed in each feature can it is identical by offers, be equal to or the alternative features of similar purpose carry out generation
Replace.
Although additionally, it will be appreciated by those of skill in the art that some embodiments in this include institute in other embodiments
Including some features rather than further feature, but the combination of the feature of different embodiment means in the scope of the present invention
Within and form different embodiments.For example, in the following claims, embodiment required for protection it is any it
One can in any combination mode using.
The present invention all parts embodiment can be realized with hardware, or with one or more processor operation
Software module realize, or with combinations thereof realize.It will be understood by those of skill in the art that can use in practice
Microprocessor or digital signal processor (DSP) are realizing in gateway according to embodiments of the present invention, proxy server, system
Some or all parts some or all functions.The present invention is also implemented as performing side as described herein
Some or all equipment of method or program of device (for example, computer program and computer program).It is such
Realize that the program of the present invention can be stored on a computer-readable medium, or there can be the shape of one or more signal
Formula.Such signal can be downloaded from internet website and be obtained, or provide on carrier signal, or with any other shape
Formula is provided.
It should be noted that above-described embodiment the present invention will be described rather than limits the invention, and ability
Field technique personnel can design alternative embodiment without departing from the scope of the appended claims.In the claims,
Any reference markss between bracket should not be configured to limitations on claims.Word " including " is not excluded the presence of not
Element listed in the claims or step.Word "a" or "an" before element does not exclude the presence of multiple such
Element.The present invention can come real by means of the hardware for including some different elements and by means of properly programmed computer
It is existing.If in the unit claim for listing equipment for drying, several in these devices can be by same hardware branch
To embody.The use of word first, second, and third does not indicate that any order.These words can be explained and be run after fame
Claim.
The invention discloses, a kind of methods of the resource that Loads Image of A1, it is characterised in that methods described includes:
The loading procedure that the loading procedure and image content that picture background is arranged shows is encapsulated to picture resource loading classes
In;
One resource management's interface of class wrapper is loaded for the picture resource;
By the corresponding picture resource loading classes of resource management's interface interchange, corresponding picture background and described is loaded
Image content shows.
A2, the method as described in claim A1, it is characterised in that after loading to the picture resource, described
Method also includes:The bitmap pixels data generated in loading procedure are stored in the bitmap set for pre-building.
A3, the method as described in claim A2, it is characterised in that the bitmap pixels data generated in loading procedure are deposited
After entering in the bitmap set, methods described also includes:
According to default recovery opportunity by resource management's interface interchange picture resource reclaimer, reclaim useless
Picture resource.
A4, the method as described in claim A3, it is characterised in that the recovery opportunity is specially the picture quilt on interface
During deletion.
A5, the method as described in claim A1, it is characterised in that when the picture resource is loaded as picture background setting
Loading when, loading method is specifically included:
When it is determined that the picture background does not load out-of-date, the view dimensions that acquisition needs show, according to the view dimensions
Judge whether the picture background needs compression;
When it is determined that the picture background needs compression, the picture background is compressed according to the first compression factor;
First bitmap pixels data of the picture background are generated according to the picture background after compression;
When it is determined that the picture background is normal picture, according to the first bitmap pair of the first bitmap pixels data genaration
As;
First bitmap object is assigned to the view for needing to show picture background.
A6, the method as described in claim A5, it is characterised in that when it is determined that the picture background need not compress,
Methods described also includes:First bitmap pixels data of the picture background are generated according to current picture background.
A7, the method as described in claim A5, it is characterised in that in loading procedure, methods described also includes:Catch
Low memory exception, when capturing abnormal, abandons loading current picture background resource.
A8, the method as described in claim A5, it is characterised in that when it is determined that the picture background was loaded, described
Method also includes:The first bitmap pixels data of the picture background are called from bitmap set.
A9, the method as described in claim A5, it is characterised in that when it is determined that the picture background is nine figure of point, institute
Stating method also includes:
Delete the first bitmap pixels data for generating;
Picture background resource is searched and is parsed using resource ID, generates the second bitmap object;
By the second bitmap object value to the view for needing display picture background.
A10, the method as described in claim A5, it is characterised in that before the resource that Loads Image, methods described is also wrapped
Include:
Resource type is judged according to resource ID;
When it is determined that the resource type is picture resource, by the corresponding picture resource of resource management's interface interchange
Loading classes, load corresponding picture resource.
A11, the method as described in claim A10, it is characterised in that the resource type includes:Picture resource, colour
Resource and XML resources.
A12, the method as described in claim A11, it is characterised in that when it is determined that the resource type be colour resource and
During XML file resource, methods described also includes:
Corresponding resource is searched and is parsed using the resource ID, generates corresponding bitmap object;
Corresponding bitmap object is assigned to the view for needing to show the picture background.
A13, the method as described in claim A5, it is characterised in that show when the picture resource is loaded as image content
During the loading shown, loading method is specifically included:
When it is determined that the image content shows does not load out-of-date, the view dimensions that acquisition needs show, according to the view
Size judges that the image content displays whether to need compression;
When it is determined that the image content is shown when needing compression, compressing the image content according to the second compression factor and show
Show;
The the second bit image prime number evidence for generating that the image content shows is shown according to the image content after compression;
When it is determined that the image content show be not point nine figure when, according to the second bit image prime number according to generate the 3rd
Figure object;
3rd bitmap object is assigned to the view for needing to show that image content shows.
B14, a kind of device of the resource that Loads Image, it is characterised in that described device includes:
First encapsulation unit, for the loading procedure encapsulation that the loading procedure that arranges picture background and image content show
Into picture resource loading classes;
Second encapsulation unit, for loading one resource management's interface of class wrapper for the picture resource;
Call unit, for by the corresponding picture resource loading classes of resource management's interface interchange, loading is corresponding
Picture background and image content show.
B15, the device as described in claim B14, it is characterised in that described device also includes storage element, when to institute
State after picture resource loaded, the storage element is used for:The bitmap pixels data generated in loading procedure are stored in advance
In the bitmap set of foundation.
B16, the device as described in claim B15, it is characterised in that the call unit is additionally operable to according to default time
Time receiving machine reclaims useless picture resource by resource management's interface interchange picture resource reclaimer.
B17, the device as described in claim B15, it is characterised in that the recovery opportunity is specially the picture on interface
When deleted.
B18, the device as described in claim B14, it is characterised in that set when the picture resource is loaded as picture background
During the loading put, first encapsulation unit includes:
First determination subelement, do not load out-of-date, view chi that acquisition needs show when the picture background for determining
It is very little, judge whether the picture background needs compression according to the view dimensions;When it is determined that when the picture background needs compression
When, the picture background is compressed according to the first compression factor;
First generates subelement, for the first bitmap pixels of the picture background are generated according to the picture background after compression
Data;
Second determination subelement, for determine the picture background be normal picture when, according to first bitmap pixels
The first bitmap object of data genaration;
First assignment subelement, for first bitmap object to be assigned to need the view for showing picture background.
B19, the device as described in claim B18, it is characterised in that when first determination subelement determines the figure
When piece background need not be compressed, the first generation subelement is additionally operable to:The picture back of the body is generated according to current picture background
First bitmap pixels data of scape.
B20, the device as described in claim B18, it is characterised in that first encapsulation unit also includes:First catches
Subelement is caught, for low memory exception is caught in loading procedure, when capturing abnormal, abandons loading the picture background
Resource.
B21, the device as described in claim B18, it is characterised in that first encapsulation unit also includes:First adjusts
With subelement, when first determination subelement, to determine that the picture background has been loaded out-of-date, and described first calls subelement to use
In the first bitmap pixels data that the picture background is called from bitmap set.
B22, the device as described in claim B18, it is characterised in that first encapsulation unit also includes:First deletes
Except subelement;When it is nine figure of point that second determination subelement determines the picture background,
Described first deletes subelement is used to delete the first bitmap pixels data for generating;
The first generation subelement is additionally operable to picture background resource is searched and parsed using resource ID, generates the second bitmap
Object;
The first assignment subelement is additionally operable to the second bitmap object value to needing to show that picture background is regarded
Figure.
B23, the device as described in claim B14, it is characterised in that before the resource that Loads Image, described first is true
Stator unit is additionally operable to judge resource type according to resource ID;
When it is determined that when the resource type is picture resource, the call unit is used for by resource management's interface
Corresponding picture resource loading classes are called, corresponding picture resource is loaded.
B24, the device as described in claim B23, it is characterised in that the resource type includes:Picture resource, colour
Resource and XML resources.
B25, the device as described in claim B23, it is characterised in that first encapsulation unit also includes:Second life
Into subelement;Wherein, when first determination subelement determines that when the resource type be colour resource and XML file resource
When,
The second generation subelement is used to corresponding resource to be searched and parsed using the resource ID, generates corresponding position
Figure object;
The first assignment subelement is additionally operable to be assigned to need the view of display picture background by corresponding bitmap object.
B26, the device as described in claim B18, it is characterised in that show when the picture resource is loaded as image content
During the loading shown, first encapsulation unit also includes:
3rd determination subelement, does not load out-of-date, the view that acquisition needs show for determining that the image content shows
According to the view dimensions, size, judges that the image content displays whether to need compression;Need when the image content shows
During compression, the image content is compressed according to the second compression factor and is shown;
3rd generates subelement, for generate that the image content shows second is shown according to the image content after compression
Bitmap pixels data;
4th determination subelement, for determining when the image content is shown as normal picture, according to the second
Figure pixel data generates the 3rd bitmap object;
Second assignment subelement, for being assigned to need to show that what image content showed regards by the 3rd bitmap object
Figure.
Claims (10)
1. a kind of method of the resource that Loads Image, it is characterised in that methods described includes:
The loading procedure that the loading procedure and image content that picture background is arranged shows is encapsulated into picture resource loading classes;
One resource management's interface of class wrapper is loaded for the picture resource;
By the corresponding picture resource loading classes of resource management's interface interchange, corresponding picture background and image content are loaded
Show.
2. the method for claim 1, it is characterised in that after loading to the picture resource, methods described is also
Including:The bitmap pixels data generated in loading procedure are stored in the bitmap set for pre-building.
3. the method for claim 1, it is characterised in that when the picture resource is loaded as the loading of picture background setting
When, loading method is specifically included:
When it is determined that the picture background does not load out-of-date, the view dimensions of acquisition needs display, according to view dimensions judgement
Whether the picture background needs compression;
When it is determined that the picture background needs compression, the picture background is compressed according to the first compression factor;
First bitmap pixels data of the picture background are generated according to the picture background after compression;
When it is determined that the picture background is normal picture, according to the first bitmap object of the first bitmap pixels data genaration;
First bitmap object is assigned to the view for needing to show picture background.
4. method as claimed in claim 3, it is characterised in that in loading procedure, methods described also includes:Catch internal memory not
Foot is abnormal, when capturing abnormal, abandons loading current picture background resource.
5. method as claimed in claim 3, it is characterised in that when the picture resource is loaded as the loading that image content shows
When, loading method is specifically included:
When it is determined that the image content shows does not load out-of-date, the view dimensions that acquisition needs show, according to the view dimensions
Judge that the image content displays whether to need compression;
When it is determined that the image content is shown when needing compression, compressing the image content according to the second compression factor and show;
The the second bit image prime number evidence for generating that the image content shows is shown according to the image content after compression;
When it is determined that the image content show be not point nine figure when, according to the second bit image prime number according to generate the 3rd bitmap pair
As;
3rd bitmap object is assigned to the view for needing to show that image content shows.
6. a kind of device of the resource that Loads Image, it is characterised in that described device includes:
First encapsulation unit, the loading procedure shown for the loading procedure that arranges picture background and image content are encapsulated to figure
In piece resource loading classes;
Second encapsulation unit, for loading one resource management's interface of class wrapper for the picture resource;
Call unit, for by the corresponding picture resource loading classes of resource management's interface interchange, loading corresponding picture
Background and image content show.
7. device as claimed in claim 6, it is characterised in that described device also includes storage element, when providing to the picture
After source is loaded, the storage element is used for:The bitmap pixels data generated in loading procedure are stored in the position for pre-building
In set of graphs.
8. device as claimed in claim 6, it is characterised in that when the picture resource is loaded as the loading of picture background setting
When, first encapsulation unit includes:
First determination subelement, do not load out-of-date, view dimensions that acquisition needs show, root when the picture background for determining
Judge whether the picture background needs compression according to the view dimensions;When it is determined that when the picture background need compression when, root
The picture background is compressed according to the first compression factor;
First generates subelement, for the first bit image prime number of the picture background is generated according to the picture background after compression
According to;
Second determination subelement, for determine the picture background be normal picture when, according to the first bitmap pixels data
Generate the first bitmap object;
First assignment subelement, for first bitmap object to be assigned to need the view for showing picture background.
9. device as claimed in claim 8, it is characterised in that first encapsulation unit also includes:First catches subelement,
For low memory exception is caught in loading procedure, when capturing abnormal, abandon loading the picture background resource.
10. device as claimed in claim 8, it is characterised in that when the picture resource be loaded as it is that image content shows plus
During load, first encapsulation unit also includes:
3rd determination subelement, does not load out-of-date, the view dimensions that acquisition needs show for determining that the image content shows,
Judge that the image content displays whether to need compression according to the view dimensions;Compression is needed when the image content shows
When, the image content is compressed according to the second compression factor and is shown;
3rd generates subelement, for showing the second bitmap for generating that the image content shows according to the image content after compression
Pixel data;
4th determination subelement, for determining when the image content is shown as normal picture, according to second bit image
The 3rd bitmap object of plain data genaration;
Second assignment subelement, for the 3rd bitmap object to be assigned to need the view for showing that image content shows.
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 true CN106598679A (en) | 2017-04-26 |
CN106598679B 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) |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107301053A (en) * | 2017-07-04 | 2017-10-27 | 武汉斗鱼网络科技有限公司 | Picture collocation method, device and electric terminal |
CN107491334A (en) * | 2017-08-29 | 2017-12-19 | 四川长虹电器股份有限公司 | A kind of tissue and loading method for preloading file |
WO2018113725A1 (en) * | 2016-12-21 | 2018-06-28 | 北京奇虎科技有限公司 | Method and device for loading picture resource, and program and medium |
CN113254131A (en) * | 2021-05-20 | 2021-08-13 | 北京有竹居网络技术有限公司 | Page background display method and device |
CN114090116A (en) * | 2021-11-08 | 2022-02-25 | 芜湖雄狮汽车科技有限公司 | Application method and device of vehicle-mounted equipment, vehicle and storage medium |
CN114398124A (en) * | 2021-12-31 | 2022-04-26 | 深圳市珍爱捷云信息技术有限公司 | Point nine-effect graph rendering method based on iOS system and related device thereof |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
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 |
Citations (7)
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 |
CN104267996A (en) * | 2014-09-29 | 2015-01-07 | 广州金山网络科技有限公司 | Image resource processing method, device and terminal |
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 |
CN105468368A (en) * | 2015-11-23 | 2016-04-06 | 浪潮软件股份有限公司 | Interface beautification method |
CN105511864A (en) * | 2015-11-30 | 2016-04-20 | 青岛海信移动通信技术股份有限公司 | Resource positioning method and device |
CN106126650A (en) * | 2016-06-24 | 2016-11-16 | 武汉斗鱼网络科技有限公司 | A kind of Web page picture based on PHP extension supports system |
Family Cites Families (6)
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 |
CN105446763B (en) * | 2014-09-30 | 2019-01-29 | Tcl集团股份有限公司 | A kind of method and system of picture load and display |
CN106598679B (en) * | 2016-12-21 | 2020-07-31 | 北京奇虎科技有限公司 | Method and device for loading picture resources |
-
2016
- 2016-12-21 CN CN201611189784.2A patent/CN106598679B/en active Active
-
2017
- 2017-12-21 WO PCT/CN2017/117675 patent/WO2018113725A1/en active Application Filing
Patent Citations (7)
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 |
CN104267996A (en) * | 2014-09-29 | 2015-01-07 | 广州金山网络科技有限公司 | Image resource processing method, device and terminal |
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 |
CN105468368A (en) * | 2015-11-23 | 2016-04-06 | 浪潮软件股份有限公司 | Interface beautification method |
CN105511864A (en) * | 2015-11-30 | 2016-04-20 | 青岛海信移动通信技术股份有限公司 | Resource positioning method and device |
CN106126650A (en) * | 2016-06-24 | 2016-11-16 | 武汉斗鱼网络科技有限公司 | A kind of Web page picture based on PHP extension supports system |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2018113725A1 (en) * | 2016-12-21 | 2018-06-28 | 北京奇虎科技有限公司 | Method and device for loading picture resource, and program and medium |
CN107301053A (en) * | 2017-07-04 | 2017-10-27 | 武汉斗鱼网络科技有限公司 | Picture collocation method, device and electric terminal |
CN107301053B (en) * | 2017-07-04 | 2020-12-15 | 武汉斗鱼网络科技有限公司 | Picture configuration method and device and electronic terminal |
CN107491334A (en) * | 2017-08-29 | 2017-12-19 | 四川长虹电器股份有限公司 | A kind of tissue and loading method for preloading file |
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 |
CN114090116A (en) * | 2021-11-08 | 2022-02-25 | 芜湖雄狮汽车科技有限公司 | Application method and device of vehicle-mounted equipment, vehicle and storage medium |
CN114398124A (en) * | 2021-12-31 | 2022-04-26 | 深圳市珍爱捷云信息技术有限公司 | Point nine-effect graph rendering method based on iOS system and related device thereof |
CN114398124B (en) * | 2021-12-31 | 2024-04-12 | 深圳市珍爱捷云信息技术有限公司 | Point nine effect graph rendering method based on iOS system and related device thereof |
Also Published As
Publication number | Publication date |
---|---|
CN106598679B (en) | 2020-07-31 |
WO2018113725A1 (en) | 2018-06-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106598679A (en) | Method and device for loading picture resources | |
CN105022750B (en) | Resource file loading method and device | |
CN106598614A (en) | Picture resource recycling method and apparatus | |
CN104750528A (en) | Management method and device for components in Android program | |
CN108229107A (en) | A kind of hulling method and container of Android platform application program | |
CN107040584A (en) | The method and device of client downloads picture | |
CN111444455A (en) | Browser compatible method, system, computer device and storage medium | |
CN111931095A (en) | Picture loading method of Android system | |
WO2018161791A1 (en) | Method and device for compressing executable file | |
CN108446300A (en) | The scan method and device of data information | |
CN112926002A (en) | Service request processing method and device | |
CN104504113A (en) | Method and device for processing information by mobile browser and mobile terminal | |
CN104378393A (en) | Resource sharing method and corresponding device | |
CN106204668B (en) | Picture decoding method and device | |
CN109460215A (en) | Application control method and device | |
CN110109687B (en) | Application installation package generation method and device | |
CN115016836A (en) | Component version management method and device, electronic equipment and system | |
CN104392408A (en) | Image display system and method | |
CN113779463A (en) | Construction method, device and equipment of android terminal page and readable storage medium | |
CN106599687A (en) | Method and device for opening Flash file in application program | |
CN106325923A (en) | Method and device for managing function plugins | |
CN106126276A (en) | A kind of call the device of transmitting assembly, method and system | |
CN108664293B (en) | Application control method and device in android system | |
CN103617052A (en) | Method and device for processing cache of application program | |
CN108829502B (en) | Method and device for realizing thread operation |
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 |