Top Banner
@tyronen #facebook Image handling in Android Tyrone Nicholas @tyronen [email protected]
23

Image handling in Android

May 11, 2015

Download

Technology

Tyrone Nicholas

How to stop images from crashing your Android app
Talk given at Devoxx London, June 13, 2014.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Image handling in Android

@tyronen@tyronen#facebook#facebook

Image handling in AndroidImage handling in Android

Tyrone Nicholas@[email protected]

Tyrone Nicholas@[email protected]

Page 2: Image handling in Android

@tyronen@tyronen#facebook#facebook

•~1/10 device RAM

•480 x 800 = 1.5 MB

Page 3: Image handling in Android

@tyronen@tyronen#facebook#facebook

GCGC

Page 4: Image handling in Android

java.lang.OutOfMemoryError

Page 5: Image handling in Android

@tyronen@tyronen#facebook#facebook

Android heapsAndroid heaps

Dalvik

•JDK

•Limited

•Slow

•Safe

Other

•Certain system

calls

•Like native

Native

•NDK

•Unlimited

•Fast

•Unsafe

Page 6: Image handling in Android

@tyronen@tyronen#facebook#facebook

What to do with images?What to do with images?

Page 7: Image handling in Android

@tyronen@tyronen#facebook#facebook

An image pipelineAn image pipeline

WebP

BMP

BMP JPG

JPG

JPG

UI thread Non-UI threads

Page 8: Image handling in Android

@tyronen@tyronen#facebook#facebook

Copying heap to heapCopying heap to heap

Page 9: Image handling in Android

@tyronen@tyronen#facebook#facebook

Using native heap from JavaUsing native heap from Java

Page 10: Image handling in Android

@tyronen@tyronen#facebook#facebook

BitmapsBitmaps

Page 11: Image handling in Android

@tyronen@tyronen#facebook#facebook

AshmemAshmem

• create

• pin

• unpin

Page 12: Image handling in Android

@tyronen@tyronen#facebook#facebook

Purgeable bitmapsPurgeable bitmaps

DrawDraw DecodeDecode PinPin

Stop drawin

g

Stop drawin

gUnpinUnpin

Page 13: Image handling in Android

@tyronen@tyronen#facebook#facebook

Using Purgeable BitmapsUsing Purgeable Bitmaps

Page 14: Image handling in Android

@tyronen@tyronen#facebook#facebook

Er, wait a minute…Er, wait a minute…

Page 15: Image handling in Android

@tyronen@tyronen#facebook#facebook

Solution #3 – Bitmap PoolingSolution #3 – Bitmap Pooling

Page 16: Image handling in Android

@tyronen@tyronen#facebook#facebook

Hang on…Hang on…

Page 17: Image handling in Android

@YourTwitterHandle#DVXFR14{session hashtag} @tyronen@tyronen#facebook#facebook

Facebook

’s

solution

Page 18: Image handling in Android

@tyronen@tyronen#facebook#facebook

From the Android NDKFrom the Android NDK

Page 19: Image handling in Android

@tyronen@tyronen#facebook#facebook

Create a new method…Create a new method…

Page 20: Image handling in Android

@tyronen@tyronen#facebook#facebook

…and use it…and use it

Page 21: Image handling in Android

@tyronen@tyronen#facebook#facebook

But afterwards…But afterwards…

Page 22: Image handling in Android
Page 23: Image handling in Android

@YourTwitterHandle#DVXFR14{session hashtag} @tyronen@tyronen#facebook#facebook

Q & A

[email protected]@tyronen