I get an image from an user which is converted into a bitmap. I then convert the bitmap to a an byte array and send it over JSON to be stored in a database. Then when the user starts the particular activity I want the image to be retrieved form the database and displayed to the user.
In the application a user is able to make a post with a title, description and an image. I want these three variables stored in the database so that when someone else views the post, they are able to see all the content. Also the image would be stored in the database as a blob, i simply use JSON to send the data to an backend application which handles all the communication with the DB.
My problem is that the bitmap that I get seems to be a reference to some memory on the device android.graphics.Bitmap@324a72b
which changes every time I run the application although I select the same image. I want to be able to retrieve the actual bitmap so it can be stored in a DB. I'm also not using as web server for storing the images since its a smaller project.
b.buttonNewItemUpImg.setOnClickListener {
val openGalleryIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
startActivityForResult(openGalleryIntent, ResultLoadImage)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == ResultLoadImage){
if (resultCode == Activity.RESULT_OK){
var temp = MediaStore.Images.Media.getBitmap(this.contentResolver, data!!.getData())
bitmap = getResizedBitmap(temp!!, maxImageSize)
b.imageView.setImageURI(data!!.getData())
}
}
}
The getResizedBitmap() function simply makes the image smaller.