当前位置: 首页>>代码示例>>Java>>正文


Java TiffReader类代码示例

本文整理汇总了Java中com.drew.imaging.tiff.TiffReader的典型用法代码示例。如果您正苦于以下问题:Java TiffReader类的具体用法?Java TiffReader怎么用?Java TiffReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TiffReader类属于com.drew.imaging.tiff包,在下文中一共展示了TiffReader类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extract

import com.drew.imaging.tiff.TiffReader; //导入依赖的package包/类
/**
 * Filter method that determines if file will contain an EPS Header.  If it does, it will read the necessary
 * data and then set the position to the beginning of the PostScript data.  If it does not, the position will not
 * be changed.  After both scenarios, the main extract method is called.
 *
 * @param inputStream InputStream containing file
 * @param metadata Metadata to add directory to and extracted data
 */
public void extract(@NotNull final InputStream inputStream, @NotNull final Metadata metadata) throws IOException
{
    RandomAccessStreamReader reader = new RandomAccessStreamReader(inputStream);
    EpsDirectory directory = new EpsDirectory();
    metadata.addDirectory(directory);

    /*
     * 0xC5D0D3C6 signifies an EPS Header block which contains 32-bytes of basic information
     *
     * 0x25215053 (%!PS) signifies an EPS File and leads straight into the PostScript
     */
    switch (reader.getInt32(0)) {
        case 0xC5D0D3C6:
            reader.setMotorolaByteOrder(false);
            int postScriptOffset = reader.getInt32(4);
            int postScriptLength = reader.getInt32(8);
            int wmfOffset = reader.getInt32(12);
            int wmfSize = reader.getInt32(16);
            int tifOffset = reader.getInt32(20);
            int tifSize = reader.getInt32(24);
            //int checkSum = reader.getInt32(28);

            // Get Tiff/WMF preview data if applicable
            if (tifSize != 0) {
                directory.setInt(EpsDirectory.TAG_TIFF_PREVIEW_SIZE, tifSize);
                directory.setInt(EpsDirectory.TAG_TIFF_PREVIEW_OFFSET, tifOffset);
                // Get Tiff metadata
                try {
                    ByteArrayReader byteArrayReader = new ByteArrayReader(reader.getBytes(tifOffset, tifSize));
                    new TiffReader().processTiff(byteArrayReader, new PhotoshopTiffHandler(metadata, null), 0);
                } catch (TiffProcessingException ex) {
                    directory.addError("Unable to process TIFF data: " + ex.getMessage());
                }
            } else if (wmfSize != 0) {
                directory.setInt(EpsDirectory.TAG_WMF_PREVIEW_SIZE, wmfSize);
                directory.setInt(EpsDirectory.TAG_WMF_PREVIEW_OFFSET, wmfOffset);
            }

            // TODO avoid allocating byte array here -- read directly from InputStream
            extract(directory, metadata, new SequentialByteArrayReader(reader.getBytes(postScriptOffset, postScriptLength)));
            break;
        case 0x25215053:
            inputStream.reset();
            extract(directory, metadata, new StreamReader(inputStream));
            break;
        default:
            directory.addError("File type not supported.");
            break;
    }
}
 
开发者ID:drewnoakes,项目名称:metadata-extractor,代码行数:59,代码来源:EpsReader.java


注:本文中的com.drew.imaging.tiff.TiffReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。