Instead of encoding and decoding to get an array of bytes, you just need to declare the array and use the get method. This is the Scala code, but hopefully it is clear:
val arr = new Array[Byte](w * h * 3) mat.get(0, 0, arr) pw.setPixels(0, 0, w, h, PixelFormat.getByteRgbInstance, arr, 0, w * 3)
This code declares an arr array of type byte[] with a size corresponding to the image h on w and 3 channels. Then the data is copied from the mat object to the array and passed to the setPixels method from the PixelWriter pw object.
source share