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

投稿

Java: Count String Occurrence

Here is the code for count up string given as a second parameter appears on string given as a first parameter. public final static int countOccurrence(String src, String search) { for(int count = 0, fromIndex = 0;;) { fromIndex = src.indexOf(search, fromIndex); if(fromIndex < 0) return count; fromIndex++; count++; } }

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