I have an imageview (containing a customer signature). I would like to extract this image to a stream so that I can convert it to a byte array (there is no file, the image is in memory). There is probably a simple way to do this but I can't seem to work it out. Can someone tell me how to do this?
Thanks Alexander, that's what I used to do but I was hoping to avoid writing to an image file. Let me explain, I want to extract the image to a stream then convert the data to base64 for storage in a database. (I was originally writing to file.dirrootexternal, but new permissions make this awkward. XUI.defaultfolder doesnt seem to work for me across different subs). How can I directly convert the image from the imageview without writing to a folder)?
'Converts an image to a bytes array (for BLOB fields).
Public Sub ImageToBytes(Image As Bitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
Image.WriteToStream(out, 100, "JPEG")
out.Close
Return out.ToBytesArray
End Sub
Originally posted a B4J/inline Java version of this in the B4J Code Snippets (https://www.b4x.com/android/forum/threads/image-to-jpeg-byte-array-with-resize-quality-options.91746/). @Erel pointed out though that the XUI library had the functionality that I was doing with Java, so I decided to...
Thankyou very much Alexander, that has worked (and greatly simplified) my program. The only problem I have is that the bitmap background displays very darkly and it is difficult to read the signature. Is it possible to extract the signature onto a white background (as originally displayed on the imageview).