本文整理汇总了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;
}
}