スキップしてメイン コンテンツに移動

投稿

C#: Read Image Metadata Using BitmapMetadata Class

Introduction In this post, I will demonstrate how to read image metadata using BitmapMetadata class in C#. Before staring explanation, we should notice there are two namespaces that can handle image in C#. System.Drawing namespace: I tested in this post System.Windows.Media.Imaging In this post, we will use classes under System.Windows.Media.Imaging. Code for Reading Image Metadata Actually code itself is quite simple :) Please see code below. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Media.Imaging; using System.Diagnostics; namespace MetadataExample { public static class ReadImageMetadataExample { public static void a(string fileName) { var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); var img = BitmapFrame.Create(fs); var metadata = img.Metadata as BitmapMetadata; Debug.WriteLine("=== metadata ===...

Java: Read Exif Metadata Using metadata-extractor

In this post, I will show you the code snippet for extracting jpeg image exif metadata using metadata-extractor . Code package com.dukesoftware.image; import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageProcessingException; import com.drew.metadata.Directory; import com.drew.metadata.Metadata; import com.drew.metadata.Tag; import java.io.File; import java.io.IOException; public class MetaDataExtractor { public static void main(String[] args) throws IOException { printMetaData(new File("c:/temp/metadata_eample.jpg")); } private static void printMetaData(File file) throws IOException { try { Metadata drewmetadata = ImageMetadataReader.readMetadata(file); for (Directory directory : drewmetadata.getDirectories()) { System.out.println("==="+directory.getClass().getName()+"==="); for (Tag tag : directory.getTags()) { System.out.p...

Java: Read Exif Metadata Using Sanselan

Recently I have been investigating image library in Java. In this post, I will show you the code snippet for extracting jpeg image exif metadata using Sanselan . Code package com.dulesoftware.image; import java.io.File; import java.io.IOException; import java.util.List; import org.apache.sanselan.ImageReadException; import org.apache.sanselan.Sanselan; import org.apache.sanselan.common.IImageMetadata; import org.apache.sanselan.common.ImageMetadata.Item; import org.apache.sanselan.formats.jpeg.JpegImageMetadata; import org.apache.sanselan.formats.tiff.TiffField; import org.apache.sanselan.formats.tiff.TiffImageMetadata; public class SanselanMetadataExample { public static void main(String[] args) throws Exception { printMeatadata(new File("c:/temp/metadata_eample.jpg")); } public static void printMeatadata(File file) throws ImageReadException, IOException { IImageMetadata sanselanmetadata = Sanselan.getMetadata(file); if (sanselan...

Java: Extract Metadata Using Apache Commons Imaging -

Introduction In the previous post , I showed available tags in ExifTagConstants, TiffTagConstants, GpsTagConstants classes. In this post, I will show you code snippet for extracting metada from jpeg using the tags. In order to run example code, you should download commons-imaging.jar from here . Somehow the official homepage of Commons Imaging doesn't provide commons-imaging.jar!! Code package com.dulesoftware.image; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; import org.apache.commons.imaging.common.IImageMetadata; import org.apache.commons.imaging.common.IImageMetadata.IImageMetadataItem; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; import org.apache.commons.imaging.formats.t...

Java: Available Tags for Extracting Metadata Using Apache Commons Imaging

Introduction In this Java: Read Image Metadata by Java Image IO post, I demonstrated the code snippet for reading image metadata only using standard java imageio library. The problem is the standard image library cannot read jpeg exif metadata as human readable format (they can be extracted as byte[] data). In this post, I will show you the code for reading jpeg exif metadata using Apache Commons Imaging library. In order to run the example code, you should download commons-imaging-1.0-SNAPSHOT.jar from commons-imaging . Basic of Read Exif Data Extracting jpeg exif metadata can be done by using findEXIFValue method in JpegImageMetadata class. The method takes TagInfo as an argument and return back TiffField . Available TagInfo static fields (constants) are mainly defined in the following class in org.apache.commons.imaging.formats.tiff.constants package: ExifTagConstants TiffTagConstants GpsTagConstants Available TagInfo in ExifTagConstants, TiffTagConstants, Gps...

Java: Read Image Metadata by Java Image IO

Introduction I have googled and wrote small code snippet for parsing and printing image metadata in Java. The biggest problem of this program (or maybe Java standard imageio library) cannot read jpeg exif data. I have found following solutions for this problem. Java Advanced Image API (Plugin) <- Looks quite obsolete. I also found the project in java.net - jai-imageio , but again not maintained for a long time :( Apache Commons Imaging : Tested in Java: Available Tags for Extracting Metadata Using Apache Commons Imaging Sanselan : Tested in Java: Read Exif Metadata Using Sanselan metadata-extractor : Testes in Java: Read Exif Metadata Using metadata-extractor J-Exiftool Both libraries are not updated recently but I guess it's because they don't need anymore enhancements. I will investigate and re-post how to use these image libraries soon... In this post, I only show you the code snippet for parsing and printing image metadata using Java standard Image API ...

C#: How to Read Image MetaData from System.Drawing.Imaging.PropertyItem

I have written simple debug code for printing out PropertyItems in System.Drawing.Image object. The key part of the code: mapping between Id property of PropertyItem and description of associated to the property item. decode PropertyItem value (byte array) to human readable format string The code itself will be shown at the bottom of this post. Below is a sample image which will be passed to the program and the corresponding output generated by the program. Property Item 1 Id: 0x10e Type: 2 Length: 17 bytes Type String: ASCII Descriotion: PropertyTagImageDescription Value : MetaData Example Property Item 2 Id: 0x131 Type: 2 Length: 7 bytes Type String: ASCII Descriotion: PropertyTagSoftwareUsed Value : Picasa Property Item 3 Id: 0x9000 Type: 7 Length: 4 bytes Type String: Undefined Descriotion: PropertyTagExifVer Value : Property Item 4 Id: 0xa002 Type: 4 Length: 4 bytes Type String: Long (3...