Does anyone know if there is an issue with setting...
# anko
b
Does anyone know if there is an issue with setting an image for an image view? I'm trying to set it by uri and it's just a gray image :(
m
blakelee: Which URI are you trying to set?
b
I was trying to get it by parsing from the uri returned by an image selected in the gallery. However I ended up getting it working without the need for permissions by decoding the uri into a bitmap then saving the bitmap as a string. Turns out reading from storage in android isn't that fun
m
saving the bitmap as a string
Looks strange. How? Why?
d
saving bitmap as a string? 😄 how?
m
I’d rather ask ‘why’. 🙂
b
I used this http://stackoverflow.com/questions/13562429/how-many-ways-to-convert-bitmap-to-string-and-vice-versa to convert it Using it like this:
Copy code
onActivityResult ...
  val selectedImageUri = data?.data
  if (selectedImageURI != null) {
    imgView.setImageURI(selectedImageUri)
    val bitmap : Bitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(selectedImageUri))
    classDetails.image = BitMapToString(bitmap)
Mostly because I want my app to not have any permissions. Then I just shove it into my database and we're good 👍
m
Why don’t you use BLOB? It has no encoding and designed for holding binary data.
b
I suppose. I'll have to see if DBflow supports it. There isn't going to be many images. Maybe 5-6 that a user will have max. That's why I'm not worried about it being inefficient. If I wanted to store a ton of images then it would be a different problem.
z
Just store as a blob (byte array) inside db. You are losing performance and space with base64. Or better, store images as local files, and save local uri into database.
1
b
I think I'll try storing them locally and having the location lookup inside the db. You are right. I tried it on my device and the base64 conversion wrecks performance