本文整理汇总了Java中org.apache.commons.imaging.ImageReadException类的典型用法代码示例。如果您正苦于以下问题:Java ImageReadException类的具体用法?Java ImageReadException怎么用?Java ImageReadException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageReadException类属于org.apache.commons.imaging包,在下文中一共展示了ImageReadException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
public static void main(String args[]) {
if (args.length != 1) {
System.err.println("Usage: Driver <inputfile>");
return;
}
try {
final File file = new File (args[0]);
JpegImageParser p = new JpegImageParser();
BufferedImage image = p.getBufferedImage(new ByteSourceFile(file), new HashMap<>());
} catch (IOException | ImageReadException e) {
System.err.println("Error reading image");
e.printStackTrace();
}
System.out.println("Done.");
}
示例2: readGps
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
private void readGps(JpegImageMetadata input, PhotoMetadata output) {
try {
TiffImageMetadata tiffData = input.getExif();
if (tiffData == null) {
LOGGER.debug("failed reading GPS since metadata contains no Exif");
return;
}
TiffImageMetadata.GPSInfo gps = input.getExif().getGPS();
if (gps == null) {
LOGGER.debug("metadata contains no GPS");
return;
}
output.setLatitude(gps.getLatitudeAsDegreesNorth());
output.setLongitude(gps.getLongitudeAsDegreesEast());
LOGGER.debug("read GPS as longitude {} and latitude {}", output.getLongitude(),
output.getLatitude());
} catch (ImageReadException ex) {
LOGGER.warn("failed reading GPS data");
}
}
示例3: Image
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
public Image(int[][] target, int dx, int dy, String URL,
int version, int mask, int rotation,
boolean randControl, long seed, boolean dither, boolean onlyDataBits, boolean saveControl) throws IOException, ImageReadException {
this.target = target;
this.dx = dx;
this.dy = dy;
this.URL = URL;
this.version = version;
this.mask = mask;
this.rotation = rotation;
this.randControl = randControl;
this.seed = seed;
this.dither = dither;
this.onlyDataBits = onlyDataBits;
this.saveControl = saveControl;
this.divider = calculateDivider();
}
示例4: readBmpHeaderInfo
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
private BmpHeaderInfo readBmpHeaderInfo(final ByteSource byteSource,
final boolean verbose) throws ImageReadException, IOException {
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
// readSignature(is);
final BmpHeaderInfo ret = readBmpHeaderInfo(is, null, verbose);
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
}
示例5: readTiffHeader
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
private TiffHeader readTiffHeader(final InputStream is) throws ImageReadException, IOException {
final int byteOrder1 = readByte("BYTE_ORDER_1", is, "Not a Valid TIFF File");
final int byteOrder2 = readByte("BYTE_ORDER_2", is, "Not a Valid TIFF File");
if (byteOrder1 != byteOrder2) {
throw new ImageReadException("Byte Order bytes don't match (" + byteOrder1 + ", " + byteOrder2 + ").");
}
final ByteOrder byteOrder = getTiffByteOrder(byteOrder1);
setByteOrder(byteOrder);
final int tiffVersion = read2Bytes("tiffVersion", is, "Not a Valid TIFF File", getByteOrder());
if (tiffVersion != 42) {
throw new ImageReadException("Unknown Tiff Version: " + tiffVersion);
}
final long offsetToFirstIFD =
0xFFFFffffL & read4Bytes("offsetToFirstIFD", is, "Not a Valid TIFF File", getByteOrder());
skipBytes(is, offsetToFirstIFD - 8, "Not a Valid TIFF File: couldn't find IFDs");
if (getDebug()) {
System.out.println("");
}
return new TiffHeader(byteOrder, tiffVersion, offsetToFirstIFD);
}
示例6: PngChunkPlte
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
public PngChunkPlte(final int length, final int chunkType, final int crc, final byte[] bytes)
throws ImageReadException, IOException {
super(length, chunkType, crc, bytes);
final ByteArrayInputStream is = new ByteArrayInputStream(bytes);
if ((length % 3) != 0) {
throw new ImageReadException("PLTE: wrong length: " + length);
}
final int count = length / 3;
rgb = new int[count];
for (int i = 0; i < count; i++) {
final int red = readByte("red[" + i + "]", is,
"Not a Valid Png File: PLTE Corrupt");
final int green = readByte("green[" + i + "]", is,
"Not a Valid Png File: PLTE Corrupt");
final int blue = readByte("blue[" + i + "]", is,
"Not a Valid Png File: PLTE Corrupt");
rgb[i] = 0xff000000 | ((0xff & red) << 16) | ((0xff & green) << 8)
| ((0xff & blue) << 0);
}
}
示例7: dumpImageFile
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
@Override
public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource)
throws ImageReadException, IOException {
pw.println("gif.dumpImageFile");
final ImageInfo imageData = getImageInfo(byteSource);
if (imageData == null) {
return false;
}
imageData.toString(pw, "");
final ImageContents blocks = readFile(byteSource, false);
pw.println("gif.blocks: " + blocks.blocks.size());
for (int i = 0; i < blocks.blocks.size(); i++) {
final GifBlock gifBlock = blocks.blocks.get(i);
this.debugNumber(pw, "\t" + i + " ("
+ gifBlock.getClass().getName() + ")",
gifBlock.blockCode, 4);
}
pw.println("");
return true;
}
示例8: getRawImageDataElements
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
private List<ImageDataElement> getRawImageDataElements(
final TiffField offsetsField, final TiffField byteCountsField)
throws ImageReadException {
final int[] offsets = offsetsField.getIntArrayValue();
final int[] byteCounts = byteCountsField.getIntArrayValue();
if (offsets.length != byteCounts.length) {
throw new ImageReadException("offsets.length(" + offsets.length
+ ") != byteCounts.length(" + byteCounts.length + ")");
}
final List<ImageDataElement> result = new ArrayList<ImageDataElement>();
for (int i = 0; i < offsets.length; i++) {
result.add(new ImageDataElement(offsets[i], byteCounts[i]));
}
return result;
}
示例9: getFieldValue
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
public short[] getFieldValue(final TagInfoSShort tag, final boolean mustExist)
throws ImageReadException {
final TiffField field = findField(tag);
if (field == null) {
if (mustExist) {
throw new ImageReadException("Required field \"" + tag.name
+ "\" is missing");
} else {
return null;
}
}
if (!tag.dataTypes.contains(field.getFieldType())) {
if (mustExist) {
throw new ImageReadException("Required field \"" + tag.name
+ "\" has incorrect type " + field.getFieldType().getName());
} else {
return null;
}
}
final byte[] bytes = field.getByteArrayValue();
return tag.getValue(field.getByteOrder(), bytes);
}
示例10: getFormatCompliance
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
@Override
public FormatCompliance getFormatCompliance(final ByteSource byteSource)
throws ImageReadException, IOException {
final boolean verbose = false;
final FormatCompliance result = new FormatCompliance(
byteSource.getDescription());
InputStream is = null;
boolean canThrow = false;
try {
is = byteSource.getInputStream();
readImageContents(is, result, verbose);
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, is);
}
return result;
}
示例11: readWbmpHeader
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
private WbmpHeader readWbmpHeader(final InputStream is)
throws ImageReadException, IOException {
final int typeField = readMultiByteInteger(is);
if (typeField != 0) {
throw new ImageReadException("Invalid/unsupported WBMP type "
+ typeField);
}
final byte fixHeaderField = readByte("FixHeaderField", is,
"Invalid WBMP File");
if ((fixHeaderField & 0x9f) != 0) {
throw new ImageReadException(
"Invalid/unsupported WBMP FixHeaderField 0x"
+ Integer.toHexString(0xff & fixHeaderField));
}
final int width = readMultiByteInteger(is);
final int height = readMultiByteInteger(is);
return new WbmpHeader(typeField, fixHeaderField, width, height);
}
示例12: parseNextString
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
private boolean parseNextString(final BasicCParser cParser,
final StringBuilder stringBuilder) throws IOException, ImageReadException {
stringBuilder.setLength(0);
String token = cParser.nextToken();
if (token.charAt(0) != '"') {
throw new ImageReadException("Parsing XPM file failed, "
+ "no string found where expected");
}
BasicCParser.unescapeString(stringBuilder, token);
for (token = cParser.nextToken(); token.charAt(0) == '"'; token = cParser
.nextToken()) {
BasicCParser.unescapeString(stringBuilder, token);
}
if (",".equals(token)) {
return true;
} else if ("}".equals(token)) {
return false;
} else {
throw new ImageReadException("Parsing XPM file failed, "
+ "no ',' or '}' found where expected");
}
}
示例13: dumpImageFile
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
@Override
public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource)
throws ImageReadException, IOException {
pw.println("pnm.dumpImageFile");
final ImageInfo imageData = getImageInfo(byteSource);
if (imageData == null) {
return false;
}
imageData.toString(pw, "");
pw.println("");
return true;
}
示例14: interpretPixel
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
@Override
public void interpretPixel(final ImageBuilder imageBuilder, final int[] samples, final int x,
final int y) throws ImageReadException, IOException {
int sample = samples[0];
if (invert) {
sample = 255 - sample;
}
final int red = sample;
final int green = sample;
final int blue = sample;
final int alpha = 0xff;
final int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
imageBuilder.setRGB(x, y, rgb);
}
示例15: getScanlineFilter
import org.apache.commons.imaging.ImageReadException; //导入依赖的package包/类
protected ScanlineFilter getScanlineFilter(FilterType filterType, int bytesPerPixel) throws ImageReadException {
switch (filterType) {
case NONE:
return new ScanlineFilterNone();
case SUB:
return new ScanlineFilterSub(bytesPerPixel);
case UP:
return new ScanlineFilterUp();
case AVERAGE:
return new ScanlineFilterAverage(bytesPerPixel);
case PAETH:
return new ScanlineFilterPaeth(bytesPerPixel);
}
return null;
}