Android Question convert file image to Byte Array

Roberto P.

Well-Known Member
Licensed User
Longtime 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
Longtime 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.
 
Upvote 0

Kwame Twum

Active Member
Licensed User
Longtime 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
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime 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
 
Upvote 0
Top