将exif数据写入jpeg流

时间:2017-08-29 07:56:27

标签: c++ jpeg libexif

我尝试在JPEG流中插入一些EXIF数据。我正在使用libexif。 libexif示例显示了如何打开文件 - >添加数据 - >然后保存文件。我所拥有的是JPEG流的指针(void * JPEGPointer)。所以我想把libexif生成的数据添加到这个指针,以便通过FTP发送它。不保存到文件。以下代码基本上是来自libexif的示例,其中一些不是我自己的memcpy()尝试。 memcpy后JPG文件已损坏,因此我无法使用任何软件打开它。我想我正在把exif复制到错误的位置。不幸的是,我不能使用任何aditional库。

// Set the image options
exif_data_set_option(exif, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
exif_data_set_data_type(exif, EXIF_DATA_TYPE_COMPRESSED);
exif_data_set_byte_order(exif, FILE_BYTE_ORDER);

// Create the mandatory EXIF fields with default data
exif_data_fix(exif);

/* Create a EXIF_TAG_USER_COMMENT tag. This one must be handled
 * differently because that tag isn't automatically created and
 * allocated by exif_data_fix(), nor can it be created using
 * exif_entry_initialize() so it must be explicitly allocated here.
 */
entry = createTag(exif, EXIF_IFD_EXIF, EXIF_TAG_USER_COMMENT,
                  sizeof(ASCII_COMMENT) + sizeof(FILE_COMMENT) - 2);
/* Write the special header needed for a comment tag */
memcpy(entry->data, ASCII_COMMENT, sizeof(ASCII_COMMENT)-1);
/* Write the actual comment text, without the trailing NUL character */
memcpy(entry->data+8, FILE_COMMENT, sizeof(FILE_COMMENT)-1);
/* createTag() happens to set the format and components correctly for
 * EXIF_TAG_USER_COMMENT, so there is nothing more to do. */
/* Get a pointer to the EXIF data block we just created */
exif_data_save_data(exif, &exif_data, &exif_data_len);
assert(exif_data != NULL);

//copy exif data to my JPEGPointer...not working like that
memcpy(JPEGPointer+ exif_data_len * sizeof(uint8_t), JPEGPointer, sizeof(JPEGPointer)+exif_data_len);

free(exif_data);
exif_data_unref(exif);

如何将EXIF数据放到JPEG数据中的正确位置?

0 个答案:

没有答案