Activityの背景をぼかす

162b7b9b7aa85f5248a9979a688f9601?s=47 Nobuhito Ibaraki
November 28, 2017
880

 Activityの背景をぼかす

162b7b9b7aa85f5248a9979a688f9601?s=128

Nobuhito Ibaraki

November 28, 2017
Tweet

Transcript

  1. © 2017 VASILY,Inc. "DUJWJUZͷഎܠΛ΅͔͢ potatotips #45ʢiOS/Android։ൃTipsڞ༗ձʣ 2017/11/28 

  2. © 2017 VASILY,Inc. ࣗݾ঺հ Ἒ໦ɹெਔ גࣜձࣾ7"4*-:ϑϩϯτΤϯυ։ൃ෦ @niba1122 ೥ɺגࣜձࣾ7"4*-:ʹ৽ଔͰೖࣾɻ ϑϩϯτΤϯυΤϯδχΞͱͯ͠8FCJ04"OESPJEͷ ֤ϓϥοτϑΥʔϜΛ୲౰͍ͯ͠Δɻ

    J04"OESPJEڞʹ։ൃྺϲ݄ɻ 
  3. © 2017 VASILY,Inc. ΍Γ͍ͨ͜ͱ "DUJWJUZͷ্ʹ৽͍͠"DUJWJUZΛදࣔͯ͠എܠΛ΅͔͢ 

  4. © 2017 VASILY,Inc. ࣮૷ͷํ਑ എܠͷΩϟϓνϟΛऔΔ Ωϟϓνϟʹ#MVSॲཧΛֻ͚Δ #MVSΛֻ͚ͨΩϟϓνϟΛ"DUJWJUZͷഎܠʹઃఆ͢Δ 

  5. © 2017 VASILY,Inc. #MVSॲཧ IUUQXXXKBZSBNCIJBDPNCMPHBOESPJECBDLHSPVOECMVS Λࢀߟʹ࣮ͯ͠૷ 

  6. © 2017 VASILY,Inc. Ωϟϓνϟͷऔಘ val view: View = window.findViewById(android.R.id.content) try

    { val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888) val c = Canvas(bitmap) view.draw(c) } catch (e: IllegalArgumentException) { e.printStackTrace() } 
  7. © 2017 VASILY,Inc. ۤ࿑ͨ͠఺ᶃ ϙοϓΞοϓͷ"DUJWJUZͰ എܠͷΩϟϓνϟΛࡱΕͳ͍ ϙοϓΞοϓͷ"DUJWJUZΛಁ໌ʹͯ͠ΩϟϓνϟΛࡱͬͯ΋ എܠͷ"DUJWJUZ͸Ωϟϓνϟ͞Εͳ͍ 

  8. © 2017 VASILY,Inc. ղܾࡦ ભҠલͷ"DUJWJUZͰΩϟϓνϟΛࡱͬͯ ϙοϓΞοϓͷ"DUJWJUZʹ౉͢ 

  9. © 2017 VASILY,Inc. Ωϟϓνϟͷ#NQ͕େ͖͗ͯ͢*OUFOUͰ౉ͤͳ͍ͷͰ ϩʔΧϧετϨʔδʹอଘͯ͠63*Λ*OUFOUͰ౉͢Α͏ʹͨ͠ val cacheDir = cacheDir val

    file = File(cacheDir, CACHE_FILE_NAME) return try { val outputStream = FileOutputStream(file) bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream) outputStream.flush() outputStream.close() Uri.fromFile(file) } catch (e: IOException) { e.printStackTrace() null } 
  10. © 2017 VASILY,Inc.

  11. © 2017 VASILY,Inc. ۤ࿑ͨ͠఺ᶄ ը૾อଘɾ#MVSॲཧ͕ॏ͍ ʢػछʹ΋ΑΔ͕ඵఔ౓͔͔Δ৔߹͕͋Δʣ ͦͷͨΊϝΠϯεϨουΛѹഭ͢Δ 

  12. © 2017 VASILY,Inc. ղܾࡦ શͯ"TZOD5BTLͰ΍Δ 

  13. © 2017 VASILY,Inc. ը૾ॲཧ͸$POUFYUΛ࢖͏ॲཧ͕ଟ͍ͷͰ "TZOD5BTLʹ"DUJWJUZΛ౉ͯ͠8FBL3FGFSFODFͰ ࢀর͢ΔΑ͏ʹͨ͠ private class AsyncBlurredCaptureLoader(activity: BlurredModalActivity)

    : AsyncTask<Uri, Unit, Drawable>() { private val activity = WeakReference(activity) override fun doInBackground(vararg params: Uri?): Drawable? { val uri = params[0] ?: return null val capture = loadCapture(uri) ?: return null val renderScript = activity.get()?.let { RenderScript.create(it) } ?: return null val blurredCapture = RSBlurProcessor(renderScript).blur(capture, 25f, 3) ?: return null val resources = activity.get()?.resources ?: return null return BitmapDrawable(resources, blurredCapture) } override fun onPostExecute(result: Drawable?) { super.onPostExecute(result) activity.get()?.onLoadBlurredCapture(result) } 
  14. © 2017 VASILY,Inc.

  15. © 2017 VASILY,Inc. ·ͱΊ w ϙοϓΞοϓͷ"DUJWJUZ͔ΒഎܠͷΩϟϓνϟ͸ࡱΕͳ͍ͷͰ
 എܠͷ"DUJWJUZͰ༧ΊΩϟϓνϟΛऔΔΑ͏ʹͨ͠ w Ωϟϓνϟը૾͕େ͖͍ͨΊʹJOUFOUͰ౉ͤͳ͍ͷͰ
 ϩʔΧϧετϨʔδʹอଘ͢ΔΑ͏ʹͨ͠

    w ը૾อଘ΍#MVSॲཧΛ"TZOD5BTLͰߦ͏ͱ͖ʹϝΠϯεϨου ͷDPOUFYU͕ඞཁͳͷͰɺ8FBL3FGFSFODFΛ࢖ͬͨ
 
  16. © 2017 VASILY,Inc.  ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠