Results 1 to 9 of 9

Thread: [RESOLVED] Adding Data to a JPEG

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  4. #4

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  6. #6

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Adding Data to a JPEG

    Nah, just wanted to know what approach you were taking.

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  9. #9

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width