Well, it seems that this solution does not work completely. Image expects a RGBA*, while I have an unsigned char*. Force-casting does not work (naturally), the image just displays some garbage.
Does anyone know an efficient way to solve this? Perhaps how to create a RawEncoder, similar to the existing JPEGEncoder?