当前位置: 首页>>代码示例>>Java>>正文


Java JpegImageParser类代码示例

本文整理汇总了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.");
}
 
开发者ID:isstac,项目名称:kelinci,代码行数:18,代码来源:Driver.java

示例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));
    // }
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:20,代码来源:App13Segment.java

示例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(),
    };
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:28,代码来源:ImageParser.java

示例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;
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:21,代码来源:JpegXmpBaseTest.java

示例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());
    }

}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:25,代码来源:NegSizeSegmentTest.java

示例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;
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:21,代码来源:IptcBaseTest.java

示例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);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:22,代码来源:IptcUpdateTest.java

示例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);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:10,代码来源:JpegXmpDumpTest.java

示例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());
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:35,代码来源:WriteExifMetadataExampleTest.java

示例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;
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:13,代码来源:ExifBaseTest.java

示例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);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:40,代码来源:IptcUpdateTest.java

示例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);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:31,代码来源:IptcUpdateTest.java

示例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());
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:35,代码来源:IptcUpdateTest.java

示例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));
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:6,代码来源:App13Segment.java

示例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());
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:45,代码来源:IptcAddTest.java


注:本文中的org.apache.commons.imaging.formats.jpeg.JpegImageParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。