Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Captions with files

Captions with files

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anthony Appleyard
    wrote on last edited by
    #1

    It seems that, among the very many properties that a file can have, is a text caption, to say what is in the file. (If it is a graphic file, it would say what the image is a picture of.) Please what are the Visual C++ functions to set and read these captions for any given file?

    L enhzflepE 3 Replies Last reply
    0
    • A Anthony Appleyard

      It seems that, among the very many properties that a file can have, is a text caption, to say what is in the file. (If it is a graphic file, it would say what the image is a picture of.) Please what are the Visual C++ functions to set and read these captions for any given file?

      L Offline
      L Offline
      Lakamraju Raghuram
      wrote on last edited by
      #2

      Quote:

      If it is a graphic file, it would say what the image is a picture of

      This is better called as 'preview' and can be retrieved as file buffer (which holds either jpeg/png/bmp image type) and can be parsed accordingly. Now like the same way, you should know what other types have as text caption to extract and parse them. Isn't it? I guess, there is no such set of methods in VC++ to do task in a generic way.

      A 1 Reply Last reply
      0
      • A Anthony Appleyard

        It seems that, among the very many properties that a file can have, is a text caption, to say what is in the file. (If it is a graphic file, it would say what the image is a picture of.) Please what are the Visual C++ functions to set and read these captions for any given file?

        enhzflepE Offline
        enhzflepE Offline
        enhzflep
        wrote on last edited by
        #3

        Never considered the problem before. After a little digging, I see that there's a .NET class for manipulating this data field (and others) I suspect you won't find a (fairly easy) way of doing this without the use of .net Here 'tis anyway: (c# .Net 4) system.windows.media.imaging.bitmapmetadata[^] (c++ .Net 4) http://msdn.microsoft.com/en-us/library/ms748873.aspx#_metadata[^]

        A 1 Reply Last reply
        0
        • L Lakamraju Raghuram

          Quote:

          If it is a graphic file, it would say what the image is a picture of

          This is better called as 'preview' and can be retrieved as file buffer (which holds either jpeg/png/bmp image type) and can be parsed accordingly. Now like the same way, you should know what other types have as text caption to extract and parse them. Isn't it? I guess, there is no such set of methods in VC++ to do task in a generic way.

          A Offline
          A Offline
          Anthony Appleyard
          wrote on last edited by
          #4

          Sorry: I did not mean a preview image. I thought that, if I (say) photographed a diver in a hardhat diving suit, that it might be possible (after I moved the image onto my computer), to attach to the image a text comment that said "Hardhat diver, Albert Dock, Liverpool", and later to retrieve the comment knowing the filename, both within a Visual C++ for Windows program.

          1 Reply Last reply
          0
          • enhzflepE enhzflep

            Never considered the problem before. After a little digging, I see that there's a .NET class for manipulating this data field (and others) I suspect you won't find a (fairly easy) way of doing this without the use of .net Here 'tis anyway: (c# .Net 4) system.windows.media.imaging.bitmapmetadata[^] (c++ .Net 4) http://msdn.microsoft.com/en-us/library/ms748873.aspx#_metadata[^]

            A Offline
            A Offline
            Anthony Appleyard
            wrote on last edited by
            #5

            What I meant is: after the usual #include's:- #include "targetver.h" pragma once #pragma comment(lib, "GdiPlus") #include "targetver.h" //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows // Windows Header Files: #include [windows.h] #include [gdiplus.h] #include [stdlib.h] #include [malloc.h] #include [memory.h] #include [tchar.h] #include [direct.h] #include [stdio.h] #include [errno.h] /* the square brackets should be angle brackets */ FILE *F; if I could wrote something like setfilecaption(F,"Hardhat diver in Albert Dock, Liverpool"); getfilecaption(F,s,n); /* get file F's caption into string s, allow n bytes for it. */

            enhzflepE 1 Reply Last reply
            0
            • A Anthony Appleyard

              What I meant is: after the usual #include's:- #include "targetver.h" pragma once #pragma comment(lib, "GdiPlus") #include "targetver.h" //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows // Windows Header Files: #include [windows.h] #include [gdiplus.h] #include [stdlib.h] #include [malloc.h] #include [memory.h] #include [tchar.h] #include [direct.h] #include [stdio.h] #include [errno.h] /* the square brackets should be angle brackets */ FILE *F; if I could wrote something like setfilecaption(F,"Hardhat diver in Albert Dock, Liverpool"); getfilecaption(F,s,n); /* get file F's caption into string s, allow n bytes for it. */

              enhzflepE Offline
              enhzflepE Offline
              enhzflep
              wrote on last edited by
              #6

              Yes indeed, I already understood that. Nonetheless, thanks for taking for the effort to ensure you'd been clear.:thumbsup: Edit: Think your keyboard is on the blink - you've got [] where there should be <>, also a } where there should be a ) Hint: You can enter the angle brackets using the html for them - i.e < is "& lt;" (andLessThanSemicolon) and > = "& gt;" (andGreaterThanSemicolon) Note: You just need to remove the space after the & character.

              A 1 Reply Last reply
              0
              • enhzflepE enhzflep

                Yes indeed, I already understood that. Nonetheless, thanks for taking for the effort to ensure you'd been clear.:thumbsup: Edit: Think your keyboard is on the blink - you've got [] where there should be <>, also a } where there should be a ) Hint: You can enter the angle brackets using the html for them - i.e < is "& lt;" (andLessThanSemicolon) and > = "& gt;" (andGreaterThanSemicolon) Note: You just need to remove the space after the & character.

                A Offline
                A Offline
                Anthony Appleyard
                wrote on last edited by
                #7

                I know about angle brackets :: I used angle brackets first, but the editor treated the texts between the angle brackets as HTML codes and dropped them, and I was in a hurry, so I quickly cut-and-pasted it to Wordpad and changed the brackets. Sorry. Please, after the usual #include's:- #include ....... FILE *F; is there something like this that I could write to set and get a file's text caption? setfilecaption(F,"Hardhat diver in Albert Dock, Liverpool"); getfilecaption(F,s,n); /* get file F's caption into string s, allow n bytes for it. */ ~~~~~~~~~~~~~~~~ Are these captions stored within the file descriptor, like the last-modified date and suchike, or are they stored in the Windows registry?

                enhzflepE 1 Reply Last reply
                0
                • A Anthony Appleyard

                  I know about angle brackets :: I used angle brackets first, but the editor treated the texts between the angle brackets as HTML codes and dropped them, and I was in a hurry, so I quickly cut-and-pasted it to Wordpad and changed the brackets. Sorry. Please, after the usual #include's:- #include ....... FILE *F; is there something like this that I could write to set and get a file's text caption? setfilecaption(F,"Hardhat diver in Albert Dock, Liverpool"); getfilecaption(F,s,n); /* get file F's caption into string s, allow n bytes for it. */ ~~~~~~~~~~~~~~~~ Are these captions stored within the file descriptor, like the last-modified date and suchike, or are they stored in the Windows registry?

                  enhzflepE Offline
                  enhzflepE Offline
                  enhzflep
                  wrote on last edited by
                  #8

                  There's been no problem caused through your use of brackets. No, there isn't something available with the interface you describe. The provided functions are available in .NET See here: reading-writing-and-photo-metadata[^] Furthermore, the data is stored in neither the directory entry (fileDescriptor) nor the Registry. See for yourself! Got a Hex-Editor? (Nope? Get one - HxD is okay and $free) I chose a JPG and did the following: 1) Right-click a photo 2) Select Properties, then the Details tab. 3) Add some unique text - I set the Camera Model field to "Canon EOS". 4) Hit apply 5) Now you can see that the photo's last modified date is the current date and time, furthermore, when you open the image in the HexEditor, you can easily find the text you entered. It should be fairly easy to implement the getfilecaption function yourself, it's likely going to involve searching the file for some kind of marker (don't think you'll have to parse the whole file, including image data yourself) so that you know where the metadata starts. Obviously, different filetypes have different structures, so you'd have to implement the function for each of the different image-file types you'd like to support. Unfortunately, it is unlikely that writing the metadata will be so simple. Here's a few pertinant links: JFIF metadata[^] (2nd search result): Does Exif metadata always get stored just after the jfif header?[^]

                  A 1 Reply Last reply
                  0
                  • enhzflepE enhzflep

                    There's been no problem caused through your use of brackets. No, there isn't something available with the interface you describe. The provided functions are available in .NET See here: reading-writing-and-photo-metadata[^] Furthermore, the data is stored in neither the directory entry (fileDescriptor) nor the Registry. See for yourself! Got a Hex-Editor? (Nope? Get one - HxD is okay and $free) I chose a JPG and did the following: 1) Right-click a photo 2) Select Properties, then the Details tab. 3) Add some unique text - I set the Camera Model field to "Canon EOS". 4) Hit apply 5) Now you can see that the photo's last modified date is the current date and time, furthermore, when you open the image in the HexEditor, you can easily find the text you entered. It should be fairly easy to implement the getfilecaption function yourself, it's likely going to involve searching the file for some kind of marker (don't think you'll have to parse the whole file, including image data yourself) so that you know where the metadata starts. Obviously, different filetypes have different structures, so you'd have to implement the function for each of the different image-file types you'd like to support. Unfortunately, it is unlikely that writing the metadata will be so simple. Here's a few pertinant links: JFIF metadata[^] (2nd search result): Does Exif metadata always get stored just after the jfif header?[^]

                    A Offline
                    A Offline
                    Anthony Appleyard
                    wrote on last edited by
                    #9

                    Thanks.

                    1 Reply Last reply
                    0
                    • A Anthony Appleyard

                      It seems that, among the very many properties that a file can have, is a text caption, to say what is in the file. (If it is a graphic file, it would say what the image is a picture of.) Please what are the Visual C++ functions to set and read these captions for any given file?

                      enhzflepE Offline
                      enhzflepE Offline
                      enhzflep
                      wrote on last edited by
                      #10

                      Hey again, I was just doing some stuff with GDI+ the other night when I came across the functions available in gdi+ that would do this. Then sometime last night I recalled this thread. Seems you don't need to be tied to using .NET, you can just use GDI+ It seems a little messy, though these pages should help you: Reading and Writing Metadata[^] EDIT:

                      #include <gdiplus.h> // needs gdiplus.lib
                      #include <gdiplus/Gdiplusimaging.h> // contains tag names and ids

                      using namespace Gdiplus;

                      void onTestButton()
                      {
                      GdiplusStartupInput gdiplusStartupInput;
                      ULONG_PTR gdiplusToken;
                      GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

                      UINT count = 0;
                      Image* image = new Image(L"test.jpg");

                      // How many properties (pieces of metadata) are in the image?
                      count = image->GetPropertyCount();
                      if(count == 0)
                      return;

                      // Allocate a buffer to receive an array of PROPIDs.
                      PROPID* propIDs = new PROPID[count];

                      image->GetPropertyIdList(count, propIDs);

                      // List the retrieved IDs.
                      for(UINT j = 0; j < count; ++j)
                      {
                      int size;
                      long *longPtr;//, myInt;
                      PropertyItem* propertyItem = NULL;
                      size = image->GetPropertyItemSize(propIDs[j]);

                      // Allocate a buffer to receive the property item.
                         propertyItem = (PropertyItem\*)malloc(size);
                      
                         // Get the property item.
                         image->GetPropertyItem(propIDs\[j\], size, propertyItem);
                      
                          //display it's value'
                          if(propertyItem->type == PropertyTagTypeASCII)
                          {
                                printf("prop tag id: 0x%04X, (string) - value is: %s.\\n", propIDs\[j\], propertyItem->value);
                          }
                          if(propertyItem->type == PropertyTagTypeLong)
                          {
                              longPtr = (long\*) propertyItem->value;
                              printf("prop tag id: 0x%04X, (long) - value is: %d.\\n", propIDs\[j\], \*longPtr);
                          }
                         free(propertyItem);
                      

                      }
                      delete [] propIDs;
                      delete image;
                      GdiplusShutdown(gdiplusToken);
                      }

                      Output:

                      prop tag id: 0x010E, (string) - value is: Title.
                      prop tag id: 0x0131, (string) - value is: GIMP 2.6.8.
                      prop tag id: 0x0132, (string) - value is: 2012:04:15 10:25:45.
                      prop tag id: 0x013B, (string) - value is: Author.
                      prop tag id: 0x8298, (string) - value

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups