[RESOLVED] Adding Data to a JPEG
I am writing a Picture Viewer program and one of the things I want to be able to do is to add descriptions to the pictures. I tried adding a description in the Comments area but that didn't work out because the file structure contains pointers to other data and changing the file length invalidated those pointers. I gave up on that approach and used an external file to hold the descriptions. That works but today I had the thought that I can just add the description to the end of the jpeg file. I tried it and I can retreive the description and doesn't seem affect the picture but I'm wondering if there's anything I'm overlooking.
Re: Adding Data to a JPEG
That may not be the best approach as you can't be sure how your data added to the file can corrupt it. I'd suggest looking at EXIF metadata. JPGs can have EXIF metadata in which you can specify various bits of information and I'd imagine that a description would be one of those pieces of information. There are tools that can do this or you can do this programmatically.
Re: Adding Data to a JPEG
Yes I've seen the Exif file structure and using what I saw I tried initially as I said the add a description, but since the description is normally near the top a description is added it pushes down all the other data and in order to be able to make that data usable again (interestingly the picture itself isn't affected) I'd have to change the pointers in the file and maybe there is an easy way but if there is I don't know about it.
Re: Adding Data to a JPEG
Well I just found some code on the web that seems to do it.
Re: [RESOLVED] Adding Data to a JPEG
Not sure what you mean by 'pointers in the file'. Are you using an external application to manage your images that depends on the file size?
What code did you find?
Re: [RESOLVED] Adding Data to a JPEG
No, I'm writing my own but it has no dependancy on file size. Here is a Wikipedia entry that talks about exif pointers and there is lots more (very obtuse to these old eyes) on the web. And I found the code at planetsourcecode but I can't find it now. If you're really interested I'll look again.
Re: [RESOLVED] Adding Data to a JPEG
Nah, just wanted to know what approach you were taking. :)
Re: [RESOLVED] Adding Data to a JPEG
you should be able to just add data to the end of the file. I would be interested in hearing how you store the original length of the file though so you know where to start overwriting the data if you change something.
1 Attachment(s)
Re: [RESOLVED] Adding Data to a JPEG
I've attached the code module that I got from planetsourcecode. It had some problems due to the lack of Option Explicit and a few other things but I corrected those.
To read a comment you do something like
Code:
lblDescription = scan_JPEG_header(strFilePath)
and to write a comment you do something like
Code:
WriteJPGComment strFilePath, txtComment.Text
The module is not very pretty but it works.