0

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

// 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 数据中的正确位置?

4

0 回答 0