本文整理汇总了Java中org.apache.sanselan.ImageInfo类的典型用法代码示例。如果您正苦于以下问题:Java ImageInfo类的具体用法?Java ImageInfo怎么用?Java ImageInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageInfo类属于org.apache.sanselan包,在下文中一共展示了ImageInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpImageFile
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
throws ImageReadException, IOException
{
pw.println("pnm.dumpImageFile");
{
ImageInfo imageData = getImageInfo(byteSource);
if (imageData == null)
return false;
imageData.toString(pw, "");
}
pw.println("");
return true;
}
示例2: doMetaData
import org.apache.sanselan.ImageInfo; //导入依赖的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);
}
}
示例3: dumpImageFile
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
throws ImageReadException, IOException
{
pw.println("tiff.dumpImageFile");
{
ImageInfo imageInfo = getImageInfo(byteSource);
if (imageInfo == null)
return false;
imageInfo.toString(pw, "");
}
pw.println("");
{
ArrayList segments = readSegments(byteSource, null, false);
if (segments == null)
throw new ImageReadException("No Segments Found.");
for (int d = 0; d < segments.size(); d++)
{
Segment segment = (Segment) segments.get(d);
NumberFormat nf = NumberFormat.getIntegerInstance();
// this.debugNumber("found, marker: ", marker, 4);
pw.println(d + ": marker: "
+ Integer.toHexString(segment.marker) + ", "
+ segment.getDescription() + " (length: "
+ nf.format(segment.length) + ")");
segment.dump(pw);
}
pw.println("");
}
return true;
}
示例4: getInfo
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
private ImageInfo getInfo() throws IOException {
if (myInfo == null) {
try {
myInfo = Sanselan.getImageInfo(getBytes());
}
catch (ImageReadException e) {
throw new IOException(e);
}
}
return myInfo;
}
示例5: process
import org.apache.sanselan.ImageInfo; //导入依赖的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;
}
示例6: getImageInfo
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public ImageInfo getImageInfo(ByteSource byteSource, Map params)
throws ImageReadException, IOException
{
// make copy of params; we'll clear keys as we consume them.
params = (params == null) ? new HashMap() : new HashMap(params);
boolean verbose = ParamMap.getParamBoolean(params, PARAM_KEY_VERBOSE,
false);
if (params.containsKey(PARAM_KEY_VERBOSE))
params.remove(PARAM_KEY_VERBOSE);
if (params.size() > 0)
{
Object firstKey = params.keySet().iterator().next();
throw new ImageReadException("Unknown parameter: " + firstKey);
}
IcnsContents contents = readImage(byteSource);
ArrayList images = IcnsDecoder.decodeAllImages(contents.icnsElements);
if (images.isEmpty())
throw new ImageReadException("No icons in ICNS file");
BufferedImage image0 = (BufferedImage) images.get(0);
return new ImageInfo("Icns", 32, new ArrayList(), ImageFormat.IMAGE_FORMAT_ICNS,
"ICNS Apple Icon Image", image0.getHeight(), "image/x-icns", images.size(),
0, 0, 0, 0, image0.getWidth(), false, true, false, ImageInfo.COLOR_TYPE_RGB,
ImageInfo.COMPRESSION_ALGORITHM_UNKNOWN);
}
示例7: dumpImageFile
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
throws ImageReadException, IOException
{
pw.println("tiff.dumpImageFile");
{
ImageInfo imageInfo = getImageInfo(byteSource);
if (imageInfo == null)
return false;
imageInfo.toString(pw, "");
}
pw.println("");
{
ArrayList segments = readSegments(byteSource, null, false);
if (segments == null)
throw new ImageReadException("No Segments Found.");
for (int d = 0; d < segments.size(); d++)
{
Segment segment = (Segment) segments.get(d);
NumberFormat nf = NumberFormat.getIntegerInstance();
// this.debugNumber("found, marker: ", marker, 4);
pw.println(d + ": marker: "
+ Integer.toHexString(segment.marker) + ", "
+ segment.getDescription() + " (length: "
+ nf.format(segment.length) + ")");
segment.dump(pw);
}
pw.println("");
}
return true;
}
示例8: dumpImageFile
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
throws ImageReadException, IOException
{
pw.println("gif.dumpImageFile");
{
ImageInfo imageData = getImageInfo(byteSource);
if (imageData == null)
return false;
imageData.toString(pw, "");
}
{
ImageContents blocks = readFile(byteSource, false);
if (blocks == null)
return false;
pw.println("gif.blocks: " + blocks.blocks.size());
for (int i = 0; i < blocks.blocks.size(); i++)
{
GIFBlock gifBlock = (GIFBlock) blocks.blocks.get(i);
this.debugNumber(pw, "\t" + i + " ("
+ gifBlock.getClass().getName() + ")",
gifBlock.blockCode, 4);
}
}
pw.println("");
return true;
}
示例9: dumpImageFile
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
throws ImageReadException, IOException
{
pw.println("bmp.dumpImageFile");
ImageInfo imageData = getImageInfo(byteSource, null);
if (imageData == null)
return false;
imageData.toString(pw, "");
pw.println("");
return true;
}
示例10: getImageInfo
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public ImageInfo getImageInfo(ByteSource byteSource, Map params)
throws ImageReadException, IOException
{
FileInfo info = readHeader(byteSource);
if (info == null)
throw new ImageReadException("PNM: Couldn't read Header");
ArrayList Comments = new ArrayList();
int BitsPerPixel = info.getBitDepth() * info.getNumComponents();
ImageFormat Format = info.getImageType();
String FormatName = info.getImageTypeDescription();
String MimeType = info.getMIMEType();
int NumberOfImages = 1;
boolean isProgressive = false;
// boolean isProgressive = (fPNGChunkIHDR.InterlaceMethod != 0);
//
int PhysicalWidthDpi = 72;
float PhysicalWidthInch = (float) ((double) info.width / (double) PhysicalWidthDpi);
int PhysicalHeightDpi = 72;
float PhysicalHeightInch = (float) ((double) info.height / (double) PhysicalHeightDpi);
String FormatDetails = info.getImageTypeDescription();
boolean isTransparent = false;
boolean usesPalette = false;
int ColorType = info.getColorType();
String compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_NONE;
ImageInfo result = new ImageInfo(FormatDetails, BitsPerPixel, Comments,
Format, FormatName, info.height, MimeType, NumberOfImages,
PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
PhysicalWidthInch, info.width, isProgressive, isTransparent,
usesPalette, ColorType, compressionAlgorithm);
return result;
}
示例11: TiffDoc
import org.apache.sanselan.ImageInfo; //导入依赖的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);
}
}
示例12: dumpImageFile
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
throws ImageReadException, IOException
{
try
{
pw.println("tiff.dumpImageFile");
{
ImageInfo imageData = getImageInfo(byteSource);
if (imageData == null)
return false;
imageData.toString(pw, "");
}
pw.println("");
// try
{
FormatCompliance formatCompliance = FormatCompliance
.getDefault();
Map params = null;
TiffContents contents = new TiffReader(true).readContents(
byteSource, params, formatCompliance);
ArrayList directories = contents.directories;
if (directories == null)
return false;
for (int d = 0; d < directories.size(); d++)
{
TiffDirectory directory = (TiffDirectory) directories
.get(d);
ArrayList entries = directory.entries;
if (entries == null)
return false;
// Debug.debug("directory offset", directory.offset);
for (int i = 0; i < entries.size(); i++)
{
TiffField field = (TiffField) entries.get(i);
field.dump(pw, d + "");
}
}
pw.println("");
}
// catch (Exception e)
// {
// Debug.debug(e);
// pw.println("");
// return false;
// }
return true;
} finally
{
pw.println("");
}
}
示例13: getImageInfo
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public ImageInfo getImageInfo(ByteSource byteSource, Map params)
throws ImageReadException, IOException
{
ImageContents blocks = readFile(byteSource, false);
if (blocks == null)
throw new ImageReadException("GIF: Couldn't read blocks");
GIFHeaderInfo bhi = blocks.gifHeaderInfo;
if (bhi == null)
throw new ImageReadException("GIF: Couldn't read Header");
ImageDescriptor id = (ImageDescriptor) findBlock(blocks.blocks,
IMAGE_SEPARATOR);
if (id == null)
throw new ImageReadException("GIF: Couldn't read ImageDescriptor");
GraphicControlExtension gce = (GraphicControlExtension) findBlock(
blocks.blocks, GRAPHIC_CONTROL_EXTENSION);
// Prefer the size information in the ImageDescriptor; it is more reliable
// than the size information in the header.
int height = id.imageWidth;
int width = id.imageHeight;
ArrayList Comments;
Comments = getComments(blocks.blocks);
int BitsPerPixel = (bhi.colorResolution + 1) * 3;
ImageFormat Format = ImageFormat.IMAGE_FORMAT_GIF;
String FormatName = "GIF Graphics Interchange Format";
String MimeType = "image/gif";
// we ought to count images, but don't yet.
int NumberOfImages = -1;
boolean isProgressive = id.interlaceFlag;
int PhysicalWidthDpi = 72;
float PhysicalWidthInch = (float) ((double) width / (double) PhysicalWidthDpi);
int PhysicalHeightDpi = 72;
float PhysicalHeightInch = (float) ((double) height / (double) PhysicalHeightDpi);
String FormatDetails = "Gif " + ((char) blocks.gifHeaderInfo.version1)
+ ((char) blocks.gifHeaderInfo.version2)
+ ((char) blocks.gifHeaderInfo.version3);
boolean isTransparent = false;
if (gce != null && gce.transparency)
isTransparent = true;
boolean usesPalette = true;
int colorType = ImageInfo.COLOR_TYPE_RGB;
String compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_LZW;
ImageInfo result = new ImageInfo(FormatDetails, BitsPerPixel, Comments,
Format, FormatName, height, MimeType, NumberOfImages,
PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
PhysicalWidthInch, width, isProgressive, isTransparent,
usesPalette, colorType, compressionAlgorithm);
return result;
}
示例14: getImageInfo
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public ImageInfo getImageInfo(ByteSource byteSource, Map params)
throws ImageReadException, IOException
{
// make copy of params; we'll clear keys as we consume them.
params = (params == null) ? new HashMap() : new HashMap(params);
boolean verbose = ParamMap.getParamBoolean(params, PARAM_KEY_VERBOSE,
false);
if (params.containsKey(PARAM_KEY_VERBOSE))
params.remove(PARAM_KEY_VERBOSE);
if (params.size() > 0)
{
Object firstKey = params.keySet().iterator().next();
throw new ImageReadException("Unknown parameter: " + firstKey);
}
ImageContents ic = readImageContents(byteSource.getInputStream(),
FormatCompliance.getDefault(), verbose);
if (ic == null)
throw new ImageReadException("Couldn't read BMP Data");
BmpHeaderInfo bhi = ic.bhi;
byte colorTable[] = ic.colorTable;
if (bhi == null)
throw new ImageReadException("BMP: couldn't read header");
int height = bhi.height;
int width = bhi.width;
ArrayList comments = new ArrayList();
// TODO: comments...
int bitsPerPixel = bhi.bitsPerPixel;
ImageFormat format = ImageFormat.IMAGE_FORMAT_BMP;
String name = "BMP Windows Bitmap";
String mimeType = "image/x-ms-bmp";
// we ought to count images, but don't yet.
int numberOfImages = -1;
// not accurate ... only reflects first
boolean isProgressive = false;
// boolean isProgressive = (fPNGChunkIHDR.InterlaceMethod != 0);
//
// pixels per meter
int physicalWidthDpi = (int) (bhi.hResolution * 1000.0 / 2.54);
float physicalWidthInch = (float) ((double) width / (double) physicalWidthDpi);
// int physicalHeightDpi = 72;
int physicalHeightDpi = (int) (bhi.vResolution * 1000.0 / 2.54);
float physicalHeightInch = (float) ((double) height / (double) physicalHeightDpi);
String formatDetails = "Bmp (" + (char) bhi.identifier1
+ (char) bhi.identifier2 + ": "
+ getBmpTypeDescription(bhi.identifier1, bhi.identifier2) + ")";
boolean isTransparent = false;
boolean usesPalette = colorTable != null;
int colorType = ImageInfo.COLOR_TYPE_RGB;
String compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_RLE;
ImageInfo result = new ImageInfo(formatDetails, bitsPerPixel, comments,
format, name, height, mimeType, numberOfImages,
physicalHeightDpi, physicalHeightInch, physicalWidthDpi,
physicalWidthInch, width, isProgressive, isTransparent,
usesPalette, colorType, compressionAlgorithm);
return result;
}
示例15: getImageInfo
import org.apache.sanselan.ImageInfo; //导入依赖的package包/类
public ImageInfo getImageInfo(ByteSource byteSource, Map params)
throws ImageReadException, IOException
{
return null;
}