C # Image Processing: Obtain the EXIF information of a digital photo (2)

Source: Internet
Author: User

Let's talk about an instance. We will discuss some common exifpropertytagids and learn how to get their values. Remember that msdn is a good resource.

Open a picture of me and scan each EXIF property item as described last time.
The ID of the first item is 0x010f. Check msdn and find that it is "null-terminated character string that specifies the manufacturer of the equipment used to record the image.". It turns out to be the camera manufacturer. Again, type = 2. Well, there is no conflict. Call the function for resolving type = 2:
Private Static string getvalueoftype2 (byte [] B)
{
Return System. Text. encoding. ASCII. getstring (B );
}

The following text is obtained:
Eastman Kodak Company

Yes, I am Kodak. Continue to look down, the second item ID is 0x0110, the old rule msdn, found to be "null-terminated character string that specifies the model name or model number of the equipment used to record the image. ". It turns out to be a model. Type or 2. Continue to call the function. The result is:
Kodak z7590 zoom digital camera
Completely correct.

Next, we can see that the type of ID = 0x8827 (ISO speed) is 3. Check msdn to find that it is a 16-bit unsigned integer. Place the value [1] to the left before the value [0.
Private Static string getvalueoftype3 (byte [] B)
{
F (B. length! = 2) Return "invalid type (3 )";
Return convert. touint16 (B [1] <8 | B [0]). tostring ();
}
My value is 80. That's right. 0xa002 and 0xa003 describe the original size of the image together and can also be obtained using this method.

Type = 4 and type = 3 are similar, except that type = 4 represents a 32-bit unsigned integer.
Private Static string getvalueoftype4 (byte [] B)
{
If (B. length! = 4) Return "invalid type (4 )";
Return convert. touint32 (B [3] <24 | B [2] <16 | B [1] <8 | B [0]). tostring ();
}
Example: Id = 0x0202 (JPEG inter length)

Type = 5, for example, the exposure time (0x829a ).
This type contains two unsigned long integer numbers. But it is not difficult to handle it. Divide 8 bytes into two parts. value [0 ~ 3] is the denominator, value [4 ~ 7] is a molecule. But don't forget to shift.
Private Static string getvalueoftype5 (byte [] B)
{
If (B. length! = 8) Return "invalid type (5 )";

Uint32 FM, Fz;
Fm = 0;
FZ = 0;

FZ = convert. touint32 (B [7] <24 | B [6] <16 | B [5] <8 | B [4]);
Fm = convert. touint32 (B [3] <24 | B [2] <16 | B [1] <8 | B [0]);

Return FM. tostring () + "/" + FZ. tostring ();
}
The exposure time of my sample photo is 1/500. Commonly used IDs of the same type include 0x829d (F-number), 0x011a, 0x011b (representing the resolution in the x/y direction respectively), and 0x9202 (Lens Aperture.

Type = 7 is messy. At least my Kodak images cannot be decoded in a uniform way. 0x9000 (EXIF version), 0xa000 (EXIF fpx version) can be calculated as follows:
Private Static string getvalueoftype7a (byte [] B)
{
String RTN = "";

For (INT I = 0; I <B. length; I ++)
{

RTN + = (char) B [I]). tostring ();

}

Return RTN;
}

But 0x9101 (EXIF compression configuration) needs to be decoded so that it is correct:
Private Static string getvalueoftype7b (byte [] B)
{
String RTN = "";

For (INT I = 0; I <B. length; I ++)
{

RTN + = B [I]. tostring ();

}

Return RTN;
}

Don't understand. Please let me know.

Finally, let's take a look at type 10. In fact, it is similar to type 5, except that type 10 is signed, so there is not much here.

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: info-contact@alibabacloud.com 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.