Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Android - Bitmapは怖くない
Search
Daichi Furiya (Wasabeef)
April 25, 2015
Programming
10
17k
Android - Bitmapは怖くない
Bitmapってどういうことが出来るか
・Picasso, GlideでのTransformationについて
・Frescoとは?
・GPUImage for Android
Daichi Furiya (Wasabeef)
April 25, 2015
Tweet
Share
More Decks by Daichi Furiya (Wasabeef)
See All by Daichi Furiya (Wasabeef)
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
1.1k
About Flutter Architecture
wasabeef
1
190
2023 Flutter/Dart Summary
wasabeef
0
51
I/O Extended 2023 - Dart と Flutter の新機能
wasabeef
0
150
I/O Extended 2023 - Flutter 活用事例
wasabeef
10
2.8k
What it Takes to be a Flutter Developer
wasabeef
0
170
FlutterKaigi 2022 Keynote
wasabeef
1
570
Flutter Hooks を使ったアプリ開発 / App Development with the Flutter Hooks
wasabeef
2
1.3k
Flutter 2021 の振り返りと今後のアプリ開発に向けて / Looking back on Flutter 2021 and for future app development.
wasabeef
4
2.1k
Other Decks in Programming
See All in Programming
Flatt Security XSS Challenge 解答・解説
flatt_security
0
730
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
170
Package Traits
ikesyo
1
210
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
700
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
870
テストコード書いてみませんか?
onopon
2
340
Rubyでつくるパケットキャプチャツール
ydah
0
160
ゼロからの、レトロゲームエンジンの作り方
tokujiros
3
1k
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
YesSQL, Process and Tooling at Scale
rocio
170
14k
How GitHub (no longer) Works
holman
312
140k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Writing Fast Ruby
sferik
628
61k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Code Review Best Practice
trishagee
65
17k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Transcript
Bitmapා͘ͳ͍ Wasabeef
About Me wasabeef CyberAgent, Inc.
Ͳ͏ߟ͑ͯBitmapා͍Ͱ͢
OutOfMemoryError…
About Bitmap
Bitmap • ը૾Λѻ͏جຊతͳAPI • BitmapFactoryͰΦϒδΣΫτੜ͢Δ • OutOfMemoryΛى͜͢ݪҼʹͳΓ͍͢
Supported Image Formats Format Encoder Decoder Details File Type JPEG
! ! Base+Progressive .jpg GIF ! .gif PNG ! ! .png BMP ! .bmp WebP !# 4.0+ !# 4.0+ .webp
About BitmapFactory.Options
inJustDecodeBounds • Bitmapͷϝλใ͚ͩऔಘ • ͋Β͔͡Ίը૾αΠζ͚ͩऔಘ͢Δ߹ͳͲ
inSampleSize • σϑΥϧτ1 • 2ʹઃఆ͢Δͱ1/2αΠζ • 4ʹઃఆ͢Δͱ1/4αΠζ • BitmapʹFilter͔͚Δ࣌ʹͱͯ༗ޮ
inPreferredConfig • BitmapΛಡΈࠐΉFormatΛࢦఆ͢Δ • σϑΥϧτ Bitmap.Config.ARGB_8888
About Bitmap.Config
ARGB_8888 • 32bit • Alpha, Red, Green, Blue ֤8bit •
Default
ARGB_4444 • 16bit • Alpha, Red, Green, Blue ֤4bit •
Deprecated in API 13
RGB_565 • 16bit • Alpha͕ͳ͍ը૾ʹ༗ޮ • ߹ʹΑͬͯARGB_8888ͷۙ͘
ALPHA_8 • 8bit • AlphaͷΈͷ߹ʹ༗ޮ
Open Source
Open Source • Universal Image Loader • Picasso • Glide
• Fresco • Volley
Picasso by Square
Picasso • Image Library • Transformation • Cache • Save
the world
Picasso Picasso.with(this) .load(“http://i.imgur.com/4rBHm4Q.jpg”) .transform(new CircleTransform()) .into(imageView);
Picasso .fit()
Picasso .centerCrop()
Picasso .resize(800,800).centerInside()
Glide by Bump (sjudd)
Glide • Picasso like • Video, Gif support • Sampling
support • BitmapPool • Thumbnail change the world
Glide Glide.with(this) .load(“http://i.imgur.com/4rBHm4Q.jpg”) .transform(new CircleTransform()) .into(imageView); #
.fitCenter() Glide
.centerCrop() Glide
.override(800, 800) Glide
Picasso and Glide Transform
Transform ը૾ΛಡΈࠐΜͰImageViewʹ දࣔ͢Δલʹը૾Λมܗͤ͞Δ
RoundedCorners
CropCircle
BitmapShader
BitmapShader public static Bitmap shader(Bitmap src) { int width =
src.getWidth(); int height = src.getHeight(); # bitmap = Bitmap.createBitmap(width, height, config); # Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); BitmapShader shader = new BitmapShader( src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); # paint.setShader(shader); RectF rectF = new RectF(margin, margin, width - margin, height - margin); canvas.drawRoundRect(recfF, radius, radius, paint); # return bitmap; }
Blur
RenderScript
RenderScript ScriptIntrinsicBlur public static Bitmap blur(Bitmap src) { int width
= src.getWidth(); int height = src.getHeight(); # bitmap = Bitmap.createBitmap(width, height, config); RenderScript rs = RenderScript.create(mContext); Allocation alloc = Allocation.createFromBitmap(rs, src); ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, alloc.getElement()); blur.setInput(alloc); blur.setRadius(mRadius); blur.forEach(alloc); alloc.copyTo(bitmap); source.recycle(); # return bitmap; }
ColorFilter
ColorFilter
ColorFilter public static Bitmap color(Bitmap src, int color) { int
width = src.getWidth(); int height = src.getHeight(); # bitmap = Bitmap.createBitmap(width, height, config); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); PorterDuffColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); canvas.drawBitmap(src, 0, 0, paint); # return bitmap; }
Open Source
Transform • picasso-transformations • glide-transformations wasabeef
GPUImage for Android CyberAgent, Inc.
GPUImage for Android • iOSͷGPUImageΛݩʹAndroidʹҠ২ • ImageViewʹରͯ͠FilterΛ͔͚ΕΔ • Filterͷछྨ70ݸ •
PhotoshopͷACVʹରԠ • API 8 (2.2+)
GPUImage for Android @Override public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity); # Uri imageUri = Uri.parse(“http://i.imgur.com/4rBHm4Q.jpg”); mGPUImage = new GPUImage(this); mGPUImage.setImage(imageUri); mGPUImage.setFilter(new GPUImageToonFilter()); # mGPUImage.saveToPictures(mGPUImage, “sample.jpg”, null); }
Fresco by Facebook
Fresco • streaming of progressive JPEGs • Gif, WebP support
• Loading customization
Fresco <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="200dp" android:layout_height="200dp" fresco:fadeDuration="300" fresco:actualImageScaleType="focusCrop" fresco:placeholderImage="@color/wait_color" fresco:placeholderImageScaleType="fitCenter" fresco:failureImage="@drawable/error"
fresco:failureImageScaleType="centerInside" fresco:retryImage="@drawable/retrying" fresco:retryImageScaleType="centerCrop" fresco:progressBarImage="@drawable/progress_bar" fresco:progressBarImageScaleType="centerInside" fresco:progressBarAutoRotateInterval="1000" fresco:backgroundImage="@color/blue" fresco:overlayImage="@drawable/watermark" fresco:pressedStateOverlayImage="@color/red" fresco:roundAsCircle="false" fresco:roundedCornerRadius="1dp" fresco:roundTopLeft="true" fresco:roundTopRight="false" fresco:roundBottomLeft="false" fresco:roundBottomRight="true" fresco:roundWithOverlayColor="@color/corner_color" fresco:roundingBorderWidth="2dp" fresco:roundingBorderColor=“@color/border_color"/>
OutOfMemoryError
࠷ޙͷखஈ
android:largeHeap=“true"
largeHeap == true? • Google+ • Amazon Kindle • Facebook
• Hulu • Tumblr • Youtube • Ameba Ownd
Wasabeef
Thanks.