T Tom Law Active Member Licensed User Longtime User Nov 28, 2023 #1 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?
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?
Alexander Stolte Expert Licensed User Longtime User Nov 28, 2023 #2 B4X: Copy Dim bm As B4XBitmap = iv.Bitmap bm.WriteToStream(File.OpenOutput(xui.DefaultFolder, "Image.jpeg", False), 100, "JPEG") Upvote 0
B4X: Copy Dim bm As B4XBitmap = iv.Bitmap bm.WriteToStream(File.OpenOutput(xui.DefaultFolder, "Image.jpeg", False), 100, "JPEG")
T Tom Law Active Member Licensed User Longtime User Nov 28, 2023 #3 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)? Upvote 0
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)?
Alexander Stolte Expert Licensed User Longtime User Nov 28, 2023 #4 B4X: Copy '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 or [B4X][XUI] Image to JPEG byte array with resize/quality options 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... www.b4x.com Upvote 0
B4X: Copy '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 or [B4X][XUI] Image to JPEG byte array with resize/quality options 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... www.b4x.com
T Tom Law Active Member Licensed User Longtime User Nov 28, 2023 #5 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). Upvote 0
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).
T Tom Law Active Member Licensed User Longtime User Nov 28, 2023 #6 ALL SORTED thank you. By changing the JPEG part of the sub routine to PNG the bitmap now displays perfectly. Upvote 0
ALL SORTED thank you. By changing the JPEG part of the sub routine to PNG the bitmap now displays perfectly.