Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. Don't use C-API. It is deprecated. Use imencode instead.
  2. You try to copy the data to a NULL pointer. You have to allocate required memory first.

Solution could be something like this (from the head):

std::vector<uchar> localBuffer;
imencode(".png", img, localBuffer, param);
char *buf = malloc(localBuffer.size());
memcpy(buf, localBuffer.data(), localBuffer.size());

Don't forget to free buf if you don't need it anymore.