Android Question How to save Preview picture in CamEx

Gary Milne

Active Member
Licensed User
Longtime User
I think this is probably easy but I cannot find an example.

In the CameraEx class there is a function called PreviewImageToJpeg(data() as byte, quality as Int) as Byte()

The first parameter (data as byte array) refers to the camera preview image formatted in YUV.

My code would be something like:
Dim jpeg() As Byte = camEx.PreviewImageToJpeg(PreviewImage, 70)

But what do I need to call in order to save the preview image into the byte array in the first place.

Any help appreciated.

Gary Milne

Active Member
Licensed User
Longtime User
Never mind, I figured it out.

You have to add the Preview Sub which receives the byte array automatically.

Sub camera1_Preview(Data() As Byte)
    Log ("Running Preview")
    Dim jpeg() As Byte = camEx.PreviewImageToJpeg(Data, 70)

    Dim bmp As Bitmap
    Dim ins As InputStream
    ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)

    'Save the screen images to a file for attachment
    Dim stream As OutputStream
    stream = File.OpenOutput( File.DirRootExternal, "File" & Counter & ".jpg",False)
    bmp.WriteToStream(stream ,50,"JPEG")
    Counter = Counter + 1
End Sub

This is just a simple example not to be taken too literally. You would want a timer or semaphore to flag the actual saving of the picture.
Upvote 0