I retrieve an image as a byte arrary stored in a database convert it to a bitmap and display it in an Imageview. I want to be able to retrieve that image from the Imageview and store it back to the database. My database retrieval code is:
TheService myService = new TheService.DataInterface();
DataSet MyPhoto = myService.GetPhoto(id);
byte[] imageBytes = (byte[])MyPhoto.Tables[0].Rows[0][0];
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
imageview.SetImageBitmap(bitmap);
At some point the image is changed and I need to store it back in the database. How would I get the image out of the imageview? Everything I've seen thus far deals with an attached drawable, there is no drawable in this case.
There doesn't seem to be a method like:
Bitmap photo = imageview.GetCurrentImage();
Any assistance would be appreciated.
**** UPDATED ****
Once I get the image I need to convert it into a byte array to save it into the database. I've tried several different methods with no success, the latest is:
using Java.Nio;
public static byte[] ImageToByte(Bitmap bitmap)
{
var bytes = new Byte[30000];
try
{
var byteBuffer = ByteBuffer.Allocate(bitmap.ByteCount);
bitmap.CopyPixelsToBuffer(byteBuffer);
bytes = byteBuffer.ToArray<byte>();
return bytes;
}
catch (Exception ex)
{
var message = ex.Message;
return bytes;
}
}
This generates an exception "Unable to cast from 'java/nio/HeapByteBuffer' to '[B'"