本文整理汇总了Java中org.apache.sanselan.Sanselan.getImageInfo方法的典型用法代码示例。如果您正苦于以下问题:Java Sanselan.getImageInfo方法的具体用法?Java Sanselan.getImageInfo怎么用?Java Sanselan.getImageInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sanselan.Sanselan
的用法示例。
在下文中一共展示了Sanselan.getImageInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doMetaData
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
private ImageInfo doMetaData(ParserResultItem result,
StreamLimiter streamLimiter) throws IOException {
try {
ImageInfo info = Sanselan.getImageInfo(
streamLimiter.getNewInputStream(),
streamLimiter.getOriginalFileName());
if (info == null)
return null;
int width = info.getWidth();
int height = info.getHeight();
long area_size = (long) width * height;
result.addField(ParserFieldEnum.image_width, width);
result.addField(ParserFieldEnum.image_height, height);
result.addField(ParserFieldEnum.image_area_size, area_size);
result.addField(ParserFieldEnum.image_number,
info.getNumberOfImages());
result.addField(ParserFieldEnum.image_format, info.getFormatName());
return info;
} catch (ImageReadException e) {
throw new IOException(e);
}
}
示例2: getInfo
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
private ImageInfo getInfo() throws IOException {
if (myInfo == null) {
try {
myInfo = Sanselan.getImageInfo(getBytes());
}
catch (ImageReadException e) {
throw new IOException(e);
}
}
return myInfo;
}
示例3: process
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
@Override
public final Image process(final Image image) throws Exception {
String imageFileName = imageDirectory + File.separatorChar + image.getId() + '.' + image.getFormat();
File file = new File(imageFileName);
if(!file.exists()) {
logger.warn("File does not exist in image directory, skipping");
imageAnnotator.annotate(image, AnnotationType.Error, AnnotationCode.BadData, "The local file was not found, so cannot be resized");
} else {
try {
ImageInfo imageInfo = Sanselan.getImageInfo(file);
Integer width = new Integer(imageInfo.getWidth());
Integer height = new Integer(imageInfo.getHeight());
logger.debug("Image " + imageFileName + " dimensions: " + width + " x " + height);
if (width > MAX_IMAGE_DIMENSION || height > MAX_IMAGE_DIMENSION) {
// shrink to no larger than MAX_IMAGE_DIMENSION * MAX_IMAGE_DIMENSION
MogrifyCmd mogrify = new MogrifyCmd();
if (searchPath != null) {
mogrify.setSearchPath(searchPath);
}
IMOperation resize = new IMOperation();
resize.addImage(imageFileName);
logger.debug("resizing to no larger than " + MAX_IMAGE_DIMENSION.intValue() + " * " + MAX_IMAGE_DIMENSION.intValue());
resize.resize(MAX_IMAGE_DIMENSION.intValue(), MAX_IMAGE_DIMENSION.intValue(),'>');
resize.addImage(imageFileName);
mogrify.run(resize);
} else {
logger.info("No need to resize image as it is smaller than " + MAX_IMAGE_DIMENSION + "px x " + MAX_IMAGE_DIMENSION + "px");
}
} catch (Exception e) {
logger.error("There was an error resizing the image", e);
imageAnnotator.annotate(image, AnnotationType.Error, AnnotationCode.BadData, "The file could not be resized");
}
}
return image;
}
示例4: TiffDoc
import org.apache.sanselan.Sanselan; //导入方法依赖的package包/类
public TiffDoc(String tiff) throws IOException, ImageReadException, InsufficientResolution, CorruptMetadata {
Iterator<ImageReader> readersIterator = ImageIO.getImageReadersByFormatName(Consts.TIF);
this.tiffImageReader = readersIterator.next();
Iterator<ImageWriter> writersIterator = ImageIO.getImageWritersByFormatName(Consts.PNG);
this.pngImageWriter = writersIterator.next();
this.tiffInputFile = new File(tiff);
final ImageInfo metadata = Sanselan.getImageInfo(tiffInputFile);
// For all EXIF tags explained, see: http://topo.math.u-psud.fr/~bousch/exifdump.py
if(Consts.MIN_DPI > metadata.getPhysicalHeightDpi() ||
Consts.MIN_DPI > metadata.getPhysicalWidthDpi()){
if(Consts.CORRUPT_DPI == metadata.getPhysicalHeightDpi() ||
Consts.CORRUPT_DPI == metadata.getPhysicalWidthDpi()) {
Logger.getLogger(TiffDoc.class.getName()).log(Level.WARNING,
"EXIF info is corrupt. Trying to read TIFF metadata");
this.dpiRes = getResolutionFromTIFFMetadata(tiffInputFile);
} else {
throw new InsufficientResolution(
"This image is unsuitable for storage. The minimum resolution is "+
Integer.toString(Consts.MIN_DPI)+". Got: ("+
Integer.toString(metadata.getPhysicalWidthDpi())+","+
Integer.toString(metadata.getPhysicalHeightDpi())+")");
}
}
this.dpiRes.put(Consts.TIFFMetadata.X_RES, metadata.getPhysicalWidthDpi());
this.dpiRes.put(Consts.TIFFMetadata.Y_RES, metadata.getPhysicalHeightDpi());
try {
this.numPages = getPageCount(tiffInputFile);
} catch (PagesInImageFileIsNull | NoSuchImageDecoder ex) {
Logger.getLogger(TiffDoc.class.getName()).log(Level.SEVERE, null, ex);
}
}