IMG to PNG buffer

Hello,

I want to avoid to save IMG (WriteImageFile) to a file and then send that file contents to a communication module.

If there is a way directly to convert IMG objet to a PNG buffer (without using hard disk), this would be easier and faster.

Thanks in advance.

Best regards,

Mikael.

Hi @Mikael,

you can use the GetLinearAccess function to get direct pixel access.
Then you can do whatever you like with the raw image data.
You can see an example in the CVB Documentation.

Regards,
Tim

Hi @TStadler, thanks for your answer.

In fact I thinking about a function “imencode” (OpenCV library).
I don’t know if CVB offers that kind of tool.
The goal will be to convert directly an IMG image into a buffer PNG ready to sent to another PC that does not know CVB (using a communication module) and will be able to display the PNG.

I can use CVB to save image on the hard disk and read PNG file contents to send it. But it would be faster to only work in memory.

I have not seen in CVB the equivalent of “imencode”, but maybe there is a way to do it. If you know it, that will help.

Best regards,

Mikael.

Hi Mikael,

so basically you want to compress a CVB IMG to PNG data and send that over the net to a different PC, then decompress it there?

I do not think there is a function for that in CVB. You would have to use GetLinearAccess to do the compression on your own (maybe using libpng) and then send it over.

Regards,
Tim

Hi Tim,
Ok, thanks for your answer.
I will have a look at libpng.
Best regards,
Mikael.