# IMG to PNG buffer

**URL:** <https://forum.commonvisionblox.com/t/img-to-png-buffer/1122>\
**Category:** C++ API\
**Created:** [May 5, 2020, 11:26am UTC](https://forum.commonvisionblox.com/t/img-to-png-buffer/1122 "2020-05-05T11:26:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikael](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Mikael](https://forum.commonvisionblox.com/u/Mikael)\
**Post date:** [May 5, 2020, 11:26am UTC](https://forum.commonvisionblox.com/t/img-to-png-buffer/1122/1 "2020-05-05T11:26:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TStadler](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/tstadler/32/308_2.png) [@TStadler](https://forum.commonvisionblox.com/u/TStadler)\
**Post date:** [May 6, 2020, 7:14am UTC](https://forum.commonvisionblox.com/t/img-to-png-buffer/1122/2 "2020-05-06T07:14:52Z")

</div>

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](https://help.commonvisionblox.com/NextGen/14.0/cvb/utility/dd/d0a/group___general.html#ga6da116729c8e1be27d5b08bee2633b65).

Regards,  
Tim

---

<div class="post-metadata">

**Author:** ![Mikael](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Mikael](https://forum.commonvisionblox.com/u/Mikael)\
**Post date:** [May 6, 2020, 7:42am UTC](https://forum.commonvisionblox.com/t/img-to-png-buffer/1122/3 "2020-05-06T07:42:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TStadler](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/tstadler/32/308_2.png) [@TStadler](https://forum.commonvisionblox.com/u/TStadler)\
**Post date:** [May 6, 2020, 9:31am UTC](https://forum.commonvisionblox.com/t/img-to-png-buffer/1122/4 "2020-05-06T09:31:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mikael](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Mikael](https://forum.commonvisionblox.com/u/Mikael)\
**Post date:** [May 6, 2020, 9:35am UTC](https://forum.commonvisionblox.com/t/img-to-png-buffer/1122/5 "2020-05-06T09:35:10Z")

</div>

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