Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Activityの背景をぼかす

Nobuhito Ibaraki
November 28, 2017
1.4k

 Activityの背景をぼかす

Nobuhito Ibaraki

November 28, 2017
Tweet

Transcript

  1. © 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() } 
  2. © 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 } 
  3. © 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) }