Maybe the saveImageIO() definition could be useful in your use case from the Processing’s source code  here. This will convert it to a byte array.
Previous posts:
- Sending byte array over processing network (Processing 3)
 - https://forum.processing.org/two/discussion/484/converting-video-capture-image-to-byte
 
Kf