本文整理汇总了Java中org.apache.commons.imaging.formats.jpeg.JpegImageParser类的典型用法代码示例。如果您正苦于以下问题:Java JpegImageParser类的具体用法?Java JpegImageParser怎么用?Java JpegImageParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JpegImageParser类属于org.apache.commons.imaging.formats.jpeg包,在下文中一共展示了JpegImageParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的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: App13Segment
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
public App13Segment(final JpegImageParser parser, final int marker, final int markerLength,
final InputStream is) throws IOException {
super(marker, markerLength, is);
this.parser = parser;
// isIPTCJpegSegment = new IptcParser().isIPTCJpegSegment(bytes);
// if (isIPTCJpegSegment)
// {
// /*
// * In practice, App13 segments are only used for Photoshop/IPTC
// * metadata. However, we should not treat App13 signatures without
// * Photoshop's signature as Photoshop/IPTC segments.
// */
// boolean verbose = false;
// boolean strict = false;
// elements.addAll(new IptcParser().parseIPTCJPEGSegment(bytes,
// verbose, strict));
// }
}
示例3: getAllImageParsers
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
/**
* Gets an array of new instances of all image parsers.
*
* @return A valid array of image parsers
*/
public static ImageParser[] getAllImageParsers() {
return new ImageParser[]{
new BmpImageParser(),
new DcxImageParser(),
new GifImageParser(),
new IcnsImageParser(),
new IcoImageParser(),
new JpegImageParser(),
new PcxImageParser(),
new PngImageParser(),
new PnmImageParser(),
new PsdImageParser(),
new RgbeImageParser(),
new TiffImageParser(),
new WbmpImageParser(),
new XbmImageParser(),
new XpmImageParser(),
// new JBig2ImageParser(),
// new TgaImageParser(),
};
}
示例4: hasJpegXmpData
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
protected static boolean hasJpegXmpData(final File file) {
if (!file.getName().toLowerCase().endsWith(".jpg"))
{
return false;
// ImageFormat format = Imaging.guessFormat(file);
// if (format != ImageFormat.IMAGE_FORMAT_JPEG)
// return false;
}
// Debug.debug("possible file", file);
try {
final ByteSource byteSource = new ByteSourceFile(file);
return new JpegImageParser().hasXmpSegment(byteSource);
} catch (final Exception e) {
// Debug.debug("Error file", file.getAbsoluteFile());
// Debug.debug(e, 4);
return false;
}
}
示例5: testCreatesNegSizeSegment
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void testCreatesNegSizeSegment() throws IOException {
byte[] bytes = new byte[8];
bytes[0] = (byte) 0xff;
bytes[1] = (byte) 0xd8;
bytes[2] = (byte) 0xe1;
bytes[3] = (byte) 0xff;
bytes[4] = (byte) 0x01;
bytes[5] = (byte) 0x00;
bytes[6] = (byte) 0x00;
bytes[7] = (byte) 0x00;
try {
InputStream inputStream = new ByteArrayInputStream(bytes);
ByteSource bs = new ByteSourceInputStream(inputStream, "NegSizeSegment");
JpegImageParser p = new JpegImageParser();
p.getBufferedImage(bs, new HashMap<String, Object>());
fail("Expecting exception: ImageReadException");
} catch (ImageReadException e) {
assertEquals("Invalid segment size", e.getMessage());
assertEquals(JpegUtils.class.getName(), e.getStackTrace()[0].getClassName());
}
}
示例6: hasIptcData
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
protected static boolean hasIptcData(final File file) {
// Debug.debug("hasIptcData file", file.getAbsoluteFile());
if (!file.getName().toLowerCase().endsWith(".jpg"))
{
return false;
// ImageFormat format = Imaging.guessFormat(file);
// if (format != ImageFormat.IMAGE_FORMAT_JPEG)
// return false;
}
try {
final ByteSource byteSource = new ByteSourceFile(file);
return new JpegImageParser().hasIptcSegment(byteSource);
} catch (final Exception e) {
// Debug.debug("Error file", file.getAbsoluteFile());
// Debug.debug(e, 4);
return false;
}
}
示例7: testRemove
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void testRemove() throws Exception {
final ByteSource byteSource = new ByteSourceFile(imageFile);
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(
byteSource, params);
assertNotNull(metadata);
final File noIptcFile = removeIptc(byteSource);
final JpegPhotoshopMetadata outMetadata = new JpegImageParser().getPhotoshopMetadata(
new ByteSourceFile(noIptcFile), params);
// FIXME should either be null or empty
assertTrue(outMetadata == null
|| outMetadata.getItems().size() == 0);
}
示例8: test
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void test() throws Exception {
final ByteSource byteSource = new ByteSourceFile(imageFile);
final Map<String, Object> params = new HashMap<>();
final String xmpXml = new JpegImageParser().getXmpXml(byteSource, params);
// TODO assert more
assertNotNull(xmpXml);
}
示例9: testOddOffsets
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
/**
* Test that there are no odd offsets in the generated TIFF images.
* @throws Exception if the test failed for a unexpected reason
*/
@Test
public void testOddOffsets() throws Exception {
Debug.debug("imageFile", imageFile.getAbsoluteFile());
final File tempFile = createTempFile("test", ".jpg");
Debug.debug("tempFile", tempFile.getAbsoluteFile());
try {
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
if (ignoreImageData) {
return;
}
new WriteExifMetadataExample().changeExifMetadata(imageFile, tempFile);
JpegImageParser parser = new JpegImageParser();
ByteSourceFile byteSource = new ByteSourceFile(tempFile);
TiffImageMetadata tiff = parser.getExifMetadata(byteSource, null);
for (TiffField tiffField : tiff.getAllFields()) {
if (!tiffField.isLocalValue()) {
int offset = tiffField.getOffset();
String tag = tiffField.getTagName();
String message = String.format("Odd offset %d, field %s", offset, tag);
boolean isOdd = (tiffField.getOffset() & 1l) == 0;
assertTrue(message, isOdd);
}
}
} catch (final ExifRewriter.ExifOverflowException e) {
Debug.debug("Ignoring unavoidable ExifOverflowException: " + e.getMessage());
Debug.debug("Error image: " + imageFile.getAbsoluteFile());
}
}
示例10: hasExifData
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
protected static boolean hasExifData(final File file) {
if (!file.getName().toLowerCase().endsWith(".jpg")) {
return false;
}
try {
final ByteSource byteSource = new ByteSourceFile(file);
return new JpegImageParser().hasExifSegment(byteSource);
} catch (final Exception e) {
return false;
}
}
示例11: testInsert
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void testInsert() throws Exception {
final ByteSource byteSource = new ByteSourceFile(imageFile);
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(
byteSource, params);
assertNotNull(metadata);
final File noIptcFile = removeIptc(byteSource);
final List<IptcBlock> newBlocks = new ArrayList<>();
final List<IptcRecord> newRecords = new ArrayList<>();
newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
newRecords.add(new IptcRecord(IptcTypes.CREDIT,
"William Sorensen"));
final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
newBlocks);
final File updated = createTempFile(imageFile.getName()
+ ".iptc.insert.", ".jpg");
try (FileOutputStream fos = new FileOutputStream(updated);
OutputStream os = new BufferedOutputStream(fos)) {
new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
noIptcFile), os, newData);
}
final ByteSource updateByteSource = new ByteSourceFile(updated);
final JpegPhotoshopMetadata outMetadata = new JpegImageParser().getPhotoshopMetadata(
updateByteSource, params);
assertNotNull(outMetadata);
assertTrue(outMetadata.getItems().size() == 2);
}
示例12: testUpdate
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void testUpdate() throws Exception {
final ByteSource byteSource = new ByteSourceFile(imageFile);
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params);
assertNotNull(metadata);
final List<IptcBlock> newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
final List<IptcRecord> newRecords = new ArrayList<>();
newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
newRecords.add(new IptcRecord(IptcTypes.CREDIT,
"William Sorensen"));
final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
newBlocks);
final File updated = writeIptc(byteSource, newData);
final ByteSource updateByteSource = new ByteSourceFile(updated);
final JpegPhotoshopMetadata outMetadata = new JpegImageParser().getPhotoshopMetadata(
updateByteSource, params);
assertNotNull(outMetadata);
assertTrue(outMetadata.getItems().size() == 2);
}
示例13: testNoChangeUpdate
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void testNoChangeUpdate() throws Exception {
final ByteSource byteSource = new ByteSourceFile(imageFile);
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params);
assertNotNull(metadata);
final List<IptcBlock> newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
final List<IptcRecord> oldRecords = metadata.photoshopApp13Data.getRecords();
final List<IptcRecord> newRecords = new ArrayList<>();
for (final IptcRecord record : oldRecords) {
if (record.iptcType != IptcTypes.CITY
&& record.iptcType != IptcTypes.CREDIT) {
newRecords.add(record);
}
}
newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
newRecords.add(new IptcRecord(IptcTypes.CREDIT, "William Sorensen"));
final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords, newBlocks);
final File updated = writeIptc(byteSource, newData);
final ByteSource updateByteSource = new ByteSourceFile(updated);
final JpegPhotoshopMetadata outMetadata = new JpegImageParser().getPhotoshopMetadata(updateByteSource, params);
assertNotNull(outMetadata);
assertTrue(outMetadata.getItems().size() == newRecords.size());
}
示例14: App13Segment
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
public App13Segment(final JpegImageParser parser, final int marker, final byte[] segmentData)
throws IOException {
this(marker, segmentData.length, new ByteArrayInputStream(
segmentData));
}
示例15: testAddIptcData
import org.apache.commons.imaging.formats.jpeg.JpegImageParser; //导入依赖的package包/类
@Test
public void testAddIptcData() throws Exception {
final ByteSource byteSource = new ByteSourceFile(imageFile);
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final JpegPhotoshopMetadata metadata = new JpegImageParser().getPhotoshopMetadata(byteSource, params);
if (metadata == null) {
// FIXME select only files with meta for this test
return;
}
final List<IptcBlock> newBlocks = new ArrayList<>();
newBlocks.addAll(metadata.photoshopApp13Data.getNonIptcBlocks());
final List<IptcRecord> oldRecords = metadata.photoshopApp13Data.getRecords();
final List<IptcRecord> newRecords = new ArrayList<>();
for (final IptcRecord record : oldRecords) {
if (record.iptcType != IptcTypes.CITY
&& record.iptcType != IptcTypes.CREDIT) {
newRecords.add(record);
}
}
newRecords.add(new IptcRecord(IptcTypes.CITY, "Albany, NY"));
newRecords.add(new IptcRecord(IptcTypes.CREDIT, "William Sorensen"));
final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords, newBlocks);
final File updated = createTempFile(imageFile.getName() + ".iptc.add.", ".jpg");
try (FileOutputStream fos = new FileOutputStream(updated);
OutputStream os = new BufferedOutputStream(fos)) {
new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
}
final ByteSource updateByteSource = new ByteSourceFile(updated);
final JpegPhotoshopMetadata outMetadata = new JpegImageParser().getPhotoshopMetadata(
updateByteSource, params);
assertNotNull(outMetadata);
assertTrue(outMetadata.getItems().size() == newRecords.size());
}