Android Question image file & custom Type

luke2012

Well-Known Member
Licensed User
Longtime User
Hi to all,
I wish to handle an image within a custom Type like this:

B4X:
Type custom (ItemName as string, ItemPic() As Byte)

Is this correct ?
If yes how to convert an image file (for eample within the File asset dir) into an array of bytes?

thanks in advance for your help
 

MTV

Member
Licensed User
I don't understand what did you mean.
Type is for custom types as you need. If you need this two properties of image , it's true.
And you can use this code to convert any file to byte.

B4X:
Sub File2Byte(Dir As String,Filename As String) As Byte()
Dim input  As InputStream
Dim output As OutputStream
Dim buff() As Byte
input = File.OpenInput(Dir,Filename)
output.InitializeToBytesArray(100000)
File.Copy2(input,output)
buff = output.ToBytesArray
output.Close
Return buff
End Sub
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User

Thanks @Erel for your great support! It is what I need

P.S.
I did only a little correction because the compiler raised an error:

B4X:
Sub File2Byte (Dir As String, FileName As String) As Byte()
Return Bit.InputStreamToBytes(File.OpenInput(Dir, FileName))
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…