Saving Image Clicked From Camera Or Loaded From Gallery In Database And Retrieving It
I am trying to save the image in imageview alongwith the other fields that user inputs. I wish to store the image in database and it will be retrieved on other page when the data i
Solution 1:
Do this to get the bitmap from the imageview:
Bitmap myBitmap= ((BitmapDrawable)image.getDrawable()).getBitmap();
then you need to convert the bitmap to a byte array:
ByteArrayOutputStreamstream=newByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
then you can store it as a blob in the DB
EDIT:
to retrieve the bimap you get the byte array from the db and convert it back to a bitmap
Cursorc= db.raw......
byte[] byteArray = c.getBlob(0);
Bitmapbm= BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Now you can just set the ImageView
bitmap to the retrieved bitmap.
Solution 2:
Instead of storing and retrieving from DB, since your usage is for one time, you should store the image in a public static variable which you can access across whole project.
publicstatic Uri publicSelectedImage; // Write this in NewPat at class level.
in your onActivityResult()
assign value to this variable as following
UriselectedImage= data.getData();
publicSelectedImage = selectedImage; // write this line.
Now from any other activity you can access this variable as following way,
UripublicImage= NewPat.publicSelectedImage;
Post a Comment for "Saving Image Clicked From Camera Or Loaded From Gallery In Database And Retrieving It"