Tika图像提取示例

本文概述

  • Tika ImageParser构造函数
  • Tika ImageParser方法
  • Tika图像解析器示例
Tika ImageParser是一个类, 用于从图像文件中提取内容和元数据。此类存储在org.apache.tika.parser.image包中。它包含构造函数和方法, 在此列出, 请参见下文。
Tika ImageParser构造函数
Constructor Description
公共ImageParser() 它用于创建类的实例。
Tika ImageParser方法以下是ImageParser类的方法。
Method Description
公共Set < MediaType> getSupportedTypes(ParseContext上下文) 当与给定的解析上下文一起使用时, 返回此解析器支持的媒体类型集。
公共无效解析(InputStream流, ContentHandler处理程序, 元数据元数据, ParseContext上下文)引发IOException, SAXException, TikaException 将文档流解析为一系列XHTML SAX事件。在给定的元数据对象中填写相关的文档元数据。
Tika图像解析器示例在此示例中, 我们提取图像文件的内容和metadat。参见示例。
package tikaexample; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.tika.exception.TikaException; import org.apache.tika.metadata.Metadata; import org.apache.tika.parser.ParseContext; import org.apache.tika.parser.jpeg.JpegParser; import org.apache.tika.sax.BodyContentHandler; import org.xml.sax.SAXException; public class ImageExample {public static void main(final String[] args) throws IOException, SAXException, TikaException {BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = http://www.srcmini.com/new Metadata(); FileInputStream inputstream = new FileInputStream(new File("srcmini.jpg")); ParseContext pcontext = new ParseContext(); JpegParserJpegParser = new JpegParser(); JpegParser.parse(inputstream, handler, metadata, pcontext); System.out.println("Document Content :" + handler.toString()); System.out.println("Document Metadata :"); String[] metadataNames = metadata.names(); for(String name : metadataNames) {System.out.println(name + ": " + metadata.get(name)); }}}

【Tika图像提取示例】输出
Document Content :Document Metadata :Exif Versi2on: 2.30Brightness: 0Compression Type: BaselineImage Description: Number of Components: 3Component 2: Cb component: Quantization table 1, Sampling factors 1 horiz/1 vertFocal Length: 4.1 mmComponent 1: Y component: Quantization table 0, Sampling factors 2 horiz/1 vertUnknown tag (0x9410): [3656 values]tiff:ResolutionUnit: InchDate/Time Original: 2015:06:11 20:53:00tiff:Make: SONYUnknown tag (0x201f): 0 0 0 0Unknown tag (0x200d): 1Flash Level: NormalComponent 3: Cr component: Quantization table 1, Sampling factors 1 horiz/1 vertFlash Exposure Compensation: 0 EVUnknown tag (0xb046): 0F-Number: f/3.5Unknown tag (0x2015): 65535Focus Mode: ManualSensitivity Type: Recommended Exposure Indextiff:BitsPerSample: 8Unknown tag (0x0002): 0x00000001Unknown tag (0x2027): 4896 3672 4375 1897

    推荐阅读