I'm trying to get an image from an url
and save that image as string to the sharedPreferences
. (I don't wanna save the image as it is. so sharedpreferences is the only option)
I'm setting the image to my imageview from url using a chunk of code copied from stackoverflow.
class DownloadImageFromInternet(var imageView: ImageView) :
AsyncTask<String, Void, Bitmap?>() {
override fun doInBackground(vararg urls: String): Bitmap? {
val imageURL = urls[0]
var image: Bitmap? = null
try {
val `in` = URL(imageURL).openStream()
image = BitmapFactory.decodeStream(`in`)
} catch (e: Exception) {
Log.e("Error Message", e.message.toString())
e.printStackTrace()
}
return image
}
override fun onPostExecute(result: Bitmap?) {
imageView.setImageBitmap(result)
imageView.invalidate()
}
}
So, I need to get the image from the imageview and save that to a variable. I've seen some stackoverflow pages where the say we have to invalidate the imageview before we can use it. Though I'm invalidating, I'm getting the previous image set to the imageView (as I need the image as soon as the image set to the imageview.
Now my question is that how can I get the bitmap from the imageView as soon as the image is set to that imageView?
Thanks in advance.