Android Question convert file image to Byte Array

Roberto P.

Well-Known Member
Licensed User
there is a tool that lets you convert an image file into byte array? This I need to send a file to print.
thanks in advance
 

Kwame Twum

Active Member
Licensed User
Hello, please I tried using this tool to convert an image (.jpg) into byte array and got the following:
error: incompatible types: byte[] cannot be converted to byte
Need help please.
 

Kwame Twum

Active Member
Licensed User
Please post the relevant code.
B4X:
Sub GetImageBytes() as Byte
  Dim bytes() As Byte = Bit.InputStreamToBytes(File.OpenInput(File.DirRootExternal,"MyApp/profile.jpg")
  Return bytes
End Sub
 

JordiCP

Well-Known Member
Licensed User
The Sub should be declared to return an array, not a single byte.;)

B4X:
Sub GetImageBytes() As Byte()  '<---- Here
  Dim bytes() As Byte = Bit.InputStreamToBytes(File.OpenInput(File.DirRootExternal,"MyApp/profile.jpg")) '<--- Also, there was a missing closing ')'
  Return bytes
End Sub
 
Top