Upload
apextgi
View
234
Download
0
Embed Size (px)
Citation preview
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 1/11
Displaying Bitmaps
Efficiently
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 2/11
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 3/11
Displaying Bitmaps Efficiently
Number of reasons why loading bitmaps in Android application
+obile de&ices typically ha&e constrained system reso!rces. Androi
can ha&e as little as +B of memory a&ailable to a single applicatio
0he Android 1ompatibility Definition Doc!ment #1DD%( 2ection 3.4.
+achine 1ompatibility gi&es the re!ired minim!m application me
&ario!s screen si,es and densities. Applications sho!ld be optimi,e
!nder this minim!m memory limit. 5owe&er( keep in mind many de
config!red with higher limits.
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 4/11
Displaying Bitmaps Efficiently
Bitmaps take !p a lot of memory( especially for rich images like
photographs. 6or example( the camera on the 7alaxy Nex!s take
to 89:8x:3 pixels #9 megapixels%. If the bitmap config!ration
is A;7B<==== #the defa!lt from the Android 8.3 onward% then lo
image into memory takes abo!t :+B of memory #89:8>:3>?
immediately exha!sting the per@app limit on some de&ices.
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 5/11
Displaying Bitmaps Efficiently
Android app $Is fre!ently re!ire se&eral bitmaps to be loaded
1omponents s!ch as ist-iew( 7rid-iew and -iewCager common
m!ltiple bitmaps on@screen at once with many more potentially
ready to show at the flick of a finger.
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 6/11
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 7/11
oading arge Bitmaps
An image with a higher resol!tion does not pro&ide any &isible benefit
takes !p precio!s memory and inc!rs additional performance o&erhea
additional on the fly scaling.B!t 'e can also decoding large bitmaps w
exceeding the per application memory limit by loading a smaller s!b s
&ersion in memory.
0he Bitmap6actory class pro&ides se&eral decoding methods s!ch as
decodeByteArray#%( decode6ile#%( decode;eso!rce#%( etc. for creating
a Bitmap from &ario!s so!rces.
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 8/11
oading arge Bitmaps
1hoose the most appropriate decode method based on image data so!
methods attempt to allocate memory for the constr!cted bitmap and t
easily res!lt in an *!t*f+emory exception.
Each type of decode method has additional signat!res that help to spe
decoding options &ia the Bitmap6actory.*ptions class.
2etting the in!stDecodeBo!nds property to tr!e while decoding a&oi
allocation( ret!rning n!ll for the bitmap ob"ect b!t setting o!t'idth(o!
o!t+ime0ype
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 9/11
oading arge Bitmaps
Example:
Bitmap6actory.*ptions options F new Bitmap6actory.*ptions#%G
options.in!stDecodeBo!nds F tr!eG
Bitmap6actory.decode;eso!rce#get;eso!rces#%( ;.id.myimage( optio
int image5eight F options.o!t5eightG
int image'idth F options.o!t'idthG
2tring image0ype F options.o!t+ime0ype
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 10/11
1ontact
8/10/2019 How to Display Bitmaps Efficiently in JAVA
http://slidepdf.com/reader/full/how-to-display-bitmaps-efficiently-in-java 11/11
0hank Ho!
Apex 07 India C&t. td. E@8 2ec@3 Noida
Apex TG Ind
E-20 , Sector 63,
0120 –4029000/9024/90
!91-99535"4E#ai$ id%
pratap&apext'
2tay 1onnected with !s for more CC0 on Android