Use vc# 2005 to add photo dates for digital photos

Source: Internet
Author: User
Tags integer

Now people have a digital camera is nothing new, let alone more than 5 million pixel digital camera is gradually become the mainstream. A digital camera can instantly convert images to a computer-recognizable image file format for browsing, sharing, and printing, compared to a conventional camera with film as a photographic medium. Although digital cameras are far more technical and convenient than normal cameras, but the author found that all of the generated image files and printed digital photos have no photo date, if you want to take photos in the future when the option is not easy to do, rummaged the digital camera instructions are not how to show in the photos Help with the date of the photo shoot. And, with the increasing number of digital image files, it will be very difficult to look at the cost of the photo albums to see when they are photographed, especially as the author of the painstaking record of children's growth process of the friends feel more so. While using my computer to browse the image files on my desktop computer, the date can be clearly displayed on the taskbar at the bottom of the window or on the summary page of the image File Properties window, but there is no tool available to draw the date of the photo to the image and to print to a digital photograph. In fact, the photo date has been saved in the image file, we need to program ourselves to get the date of the photo and draw it out in the lower right corner of the image, then save the newly generated image file and copy it to the digital photo print store for printing, we can get the digital photo with the date of the photo, the following figure:

First, Introduction

Most digital cameras now store images in JPG format, and information such as photo dates is collectively known as EXIF information. EXIF is an abbreviation for English exchangeableimagefile (exchangeable image file), originally developed by the Japan Electronic Industry Development Association (jeida--japanelectronicindustrydevelopmentassociation) , when Jeita decided to set up a set of standards for digital camera manufacturers, with the development of digital cameras, the trend of popularization is becoming more and more obvious, so Jeita to the EXIF standard has been upgraded, currently the latest version of 2.2. In fact, Exif is also an image file format, EXIF information is a digital camera in the process of capturing a series of information, and then put information in a JPG file or TIFF file head, that is, EXIF information is embedded in the image file format in a group of shooting parameters, mainly including the aperture of photography, Shutter, ISO, photo date time and other information related to the photographic conditions, camera brand models, color coding, even recorded during the shooting and the Global Positioning System (GPS) and other information. Simply put, it's like a instamatics date print function, except that the information recorded in the EXIF information is more detailed and complete. It should be noted that digital image files edited with image processing software may lose their EXIF information.

So, to draw the date on the image, you must first read the EXIF information, and then draw the date of the photo to the image surface, we will use the 5 million pixel resolution of 2592x1944 JPG image files as objects, using Visual Studio. Net 2005 of C # To write a tool program to implement the above functionality.

Second, technical background

EXIF information is stored as a key-value pair in the head of a digital JPG image file, in the. NET platform all image file header information is collectively referred to as metadata, we can use GDI + to read existing metadata, you can also write new metadata to the image file. GDI + stores a separate metadata segment in the PropertyItem object, reading the PropertyItems property of the Image object to retrieve all the metadata from a file. The PropertyItems property returns an array of PropertyItem objects. The PropertyItem object has the following four properties: Id, Value, Len, and Type. ID is used to identify the token for the metadata item, and the following table shows the values of some IDs:

hexadecimal value description
image title
device manufacturer
0x0110 device model
0x0132 photo time
0x829a exif exposure time
0x 5090 luminance table


value is an array value, and the format of the values is determined by the Type property. The length of the array, in bytes, of the value pointed to by the Len property. The Type property points to the data type of the value in the array. The following table shows the format indicated by the Type property value:

/tr> tr> TD style= "BORDER:0;PADDING:0;" >
value description
a Byte
2 ascii array of encoded Byte objects
16-bit integer
4 32-bit integer
6 " > not use
not using

The ID value we are interested in is 0x0132, which is the picture taking time, the corresponding tag is propertytagdatetime, and in the online MSDN we found a more detailed description of GDI + for the EXIF attribute. The type of the Propertytagdatetime value is Propertytagtypeascii, which holds the data in ASCII encoding, which we decode with ASCII after fetching the data, converting some column bytes to a date/time string.

Before we proceed to the next step, we can first use text editing software such as UltraEdit to open the picture file to manipulate the actual look at what the document is, the following figure:

We found that the date format was: 2006:06:07 16:33:41, this format is neither a standard date/time format nor the current system format, so the date/time format needs to be formatted.

After getting the date/time of the photo, create the graphics object from the specified picture file, and on the Graphics object, draw the photo date/time we acquired earlier.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.