Skip to content

Instantly share code, notes, and snippets.

@crypticminds
Created January 5, 2020 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crypticminds/3c73d429124fbd1d700b56f4ea957e32 to your computer and use it in GitHub Desktop.
Save crypticminds/3c73d429124fbd1d700b56f4ea957e32 to your computer and use it in GitHub Desktop.
package com.arcane.coldstoragecache.converter.impl
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Base64
import android.util.Log
import com.arcane.coldstoragecache.converter.IConverter
/**
* An example converter that will convert the stored string
* into a bitmap.
*
*/
class StringToBitmapConverter : IConverter<Any?> {
/**
* The function will convert the string stored in the cache
* into the required bitmap.
*/
override fun convert(cachedString: String): Bitmap? {
return try {
val encodeByte: ByteArray = Base64.decode(cachedString, Base64.DEFAULT)
BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.size)
} catch (e: Exception) {
Log.e("ERROR", "Failed to convert cached string to bitmap")
return null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment