Android Question ToBytes can only be called after InitializeToBytesArray....

Yayou49

Active Member
Licensed User
Hi,

I'm in the sub Camera_PictureTaken.
When the picture is taken, I try to do:

- Save the taken picture in a file
- rotate and resize my picture
- save my new picture in a new file
- create a MAP

With line "Input.Put("Fic",Out.ToBytesArray)" (in my code below), system give me an error:

B4X:
ToBytes can only be called after InitializeToBytesArray.

While "Out" is initialized with Out.initializeToBytesArray(0)

I have 2 questions:

- Why this error ?
- is there a better way to do what I want to do ?

B4X:
Sub Camera_PictureTaken (Data() As Byte)
   
    camera.StartPreview
   
    Dim Myout As OutputStream
    Myout.InitializeToBytesArray(0)
    Myout = File.OpenOutput(File.DirRootExternal, 1.jpg, False)
    Myout.WriteBytes(Data, 0, Data.Length)
    Myout.Close   
   
    Dim MyPic As Bitmap
    MyPic.Initialize(File.DirRootExternal, 1.jpg)
    MyPic.Resize(800,600,True)
    MyPic.Rotate(90)
   
    Dim Out As OutputStream
    Out.initializeToBytesArray(0)
    Out = File.OpenOutput(File.DirRootExternal, 2.jpg, False)
    MyPic.WriteToStream(Out, 100, "JPEG")
    Out.Close
   
    Dim Input As Map
    Input.Initialize
    Input.Put("IdRma",OnSiteMain.IdRMA)
    Input.Put("Fic",Out.ToBytesArray)

    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize(Input)
   
    ' code to send to WS
 
Top