本文整理汇总了Java中org.apache.commons.imaging.Imaging类的典型用法代码示例。如果您正苦于以下问题:Java Imaging类的具体用法?Java Imaging怎么用?Java Imaging使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Imaging类属于org.apache.commons.imaging包,在下文中一共展示了Imaging类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processImage
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
private byte[] processImage(byte[] imageBytes, List<Rectangle> areasToBeCleaned) {
if (areasToBeCleaned.isEmpty()) {
return imageBytes;
}
try {
BufferedImage image = Imaging.getBufferedImage(imageBytes);
ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);
cleanImage(image, areasToBeCleaned);
// Apache can only read JPEG, so we should use awt for writing in this format
if (imageInfo.getFormat() == ImageFormats.JPEG) {
return getJPGBytes(image);
} else {
Map<String, Object> params = new HashMap<String, Object>();
if (imageInfo.getFormat() == ImageFormats.TIFF) {
params.put(ImagingConstants.PARAM_KEY_COMPRESSION, TiffConstants.TIFF_COMPRESSION_LZW);
}
return Imaging.writeImageToBytes(image, imageInfo.getFormat(), params);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: write
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Override
public void write(IIOMetadata iioMetadata, IIOImage iioImage, ImageWriteParam param)
throws IOException {
if (ios == null) {
throw new IllegalArgumentException(Messages.getString("imageio.7F"));
}
RenderedImage img = null;
if (!iioImage.hasRaster()) {
img = iioImage.getRenderedImage();
if (img instanceof BufferedImage) {
sourceRaster = ((BufferedImage) img).getRaster();
} else {
sourceRaster = img.getData();
}
} else {
sourceRaster = iioImage.getRaster();
}
Map params = new HashMap();
try {
Imaging.writeImage((BufferedImage)img,
wrapOutput(ios),//(OutputStream)ios,
ImageFormats.JPEG,
params);
} catch (ImageWriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: read
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
public static BufferedImage read(File input) throws IOException {
if (input == null) {
throw new IllegalArgumentException(Messages.getString("imageio.52"));
}
/* String name=input.getName().toLowerCase();
if(name.endsWith(".png")) {
PngImageParser parser = new PngImageParser();
try {
return parser.getBufferedImage(input, new HashMap());
} catch (ImageReadException e) {
throw new IOException(e);
}
}
else if(name.endsWith(".gif")) {
GifImageParser parser = new GifImageParser();
try {
return parser.getBufferedImage(input, new HashMap());
} catch (ImageReadException e) {
throw new IOException(e);
}
}*/
try {
return Imaging.getBufferedImage(input);
} catch (ImageReadException e) {
// TODO Auto-generated catch block
throw new IOException(e);
}
/* ImageInputStream stream = createImageInputStream(input);
return read(stream);*/
}
示例4: setExifGPSTag
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
/**
* This method sets the EXIF the of the JPEG file and outputs it to given directory.
* @param jpegImageFile
* Input jpeg file.
* @param dst
* output jpeg file.
* @param longitude
* Longitude to be tagged.
* @param latitude
* Latitude to be tagged.
* @throws IOException
* @throws ImageReadException
* @throws ImageWriteException
*/
public static void setExifGPSTag(final File jpegImageFile, final File dst, final double longitude, final double latitude) throws IOException,
ImageReadException, ImageWriteException {
OutputStream os = null;
boolean canThrow = false;
try {
final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile);
final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
TiffOutputSet outputSet = setTiffOutputSet(jpegMetadata, longitude, latitude);
os = new FileOutputStream(dst);
os = new BufferedOutputStream(os);
new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet);
canThrow = true;
} finally {
IoUtils.closeQuietly(canThrow, os);
}
}
示例5: getExif
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
private static TiffImageMetadata getExif(final File file) {
TiffImageMetadata exif = null;
try {
final IImageMetadata metadata = Imaging.getMetadata(file);
if (metadata != null) {
final JpegImageMetadata jpegMetadata
= (JpegImageMetadata) metadata;
exif = jpegMetadata.getExif();
} else {
log(Level.WARNING, String.format(
"No metadata found for file %s", file));
}
}
catch (final ImageReadException | IOException ex) {
Logger.getLogger(PhotoLoader.class.getName()).
log(Level.SEVERE, null, ex);
}
return exif;
}
示例6: checkJpeg
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
/**
* Validate that the file is a JPEG file.
*
* @param jpegImageFileName the file to be validated.
* @throws IOException thrown if the file is no jpg.
*/
public static void checkJpeg(@Nullable final String jpegImageFileName) throws IOException {
if (jpegImageFileName == null) {
throw new IOException("Error in checkJpeg - no image passed.");
}
File file = new File(jpegImageFileName);
String mimeType;
try {
mimeType = Imaging.getImageInfo(file).getMimeType();
if (!"image/jpeg".equals(mimeType)) {
throw new IOException("Bad MIME type " + mimeType + " - can handle metadata only for image/jpeg.");
}
}
catch (ImageReadException e) {
throw new IOException(e);
}
}
示例7: testExtractPagesFromMultiPageTiff
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
/**
* Load a multi-page TIFF image and split it into its individual pages.
*/
@Test
public void testExtractPagesFromMultiPageTiff() throws Exception {
File sourceImageFile = getImageFile("tiff", "test-multi-gray-compression-type-4.tiff");
List<BufferedImage> bufferedImageList = Imaging.getAllBufferedImages(sourceImageFile);
for (BufferedImage bufferedImage : bufferedImageList) {
assertValidBufferedImage(bufferedImage);
}
assertEquals("Expect to have 2 pages", 2, bufferedImageList.size());
}
示例8: test
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Test
public void test() throws Exception {
Debug.debug("start");
final List<File> images = getXbmImages();
for (final File imageFile : images) {
Debug.debug("imageFile", imageFile);
final ImageMetadata metadata = Imaging.getMetadata(imageFile);
Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null)
final Map<String, Object> params = new HashMap<>();
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
assertNotNull(imageInfo);
final BufferedImage image = Imaging.getBufferedImage(imageFile);
assertNotNull(image);
}
}
示例9: checkFields
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
private void checkFields(final byte[] file) throws Exception {
final TiffImageMetadata metadata = toTiffMetadata(Imaging.getMetadata(file));
// field values may be duplicated between directories, we have to check all
final List<Object> authorValues = new ArrayList<>();
final List<Object> commentValues = new ArrayList<>();
final List<Object> subjectValues = new ArrayList<>();
final List<Object> titleValues = new ArrayList<>();
for (final TiffDirectory d : metadata.contents.directories) {
titleValues.add(d.getFieldValue(MicrosoftTagConstants.EXIF_TAG_XPTITLE, false));
authorValues.add(d.getFieldValue(MicrosoftTagConstants.EXIF_TAG_XPAUTHOR, false));
commentValues.add(d.getFieldValue(MicrosoftTagConstants.EXIF_TAG_XPCOMMENT, false));
subjectValues.add(d.getFieldValue(MicrosoftTagConstants.EXIF_TAG_XPSUBJECT, false));
}
assertTrue(authorValues.contains(AUTHOR));
assertTrue(commentValues.contains(COMMENT));
assertTrue(subjectValues.contains(SUBJECT));
assertTrue(titleValues.contains(TITLE));
}
示例10: test
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Test
public void test() throws Exception {
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final JpegImageMetadata metadata = (JpegImageMetadata) Imaging.getMetadata(imageFile, params);
assertNotNull(metadata);
assertNotNull(metadata.getPhotoshop());
metadata.getPhotoshop().dump();
final JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
final List<IptcRecord> oldRecords = psMetadata.photoshopApp13Data.getRecords();
Debug.debug();
for (final IptcRecord record : oldRecords) {
if (record.iptcType != IptcTypes.CITY) {
Debug.debug("Key: " + record.iptcType.getName() + " (0x"
+ Integer.toHexString(record.iptcType.getType())
+ "), value: " + record.getValue());
}
}
Debug.debug();
}
示例11: test
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Test
public void test() throws Exception {
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final ImageMetadata metadata = Imaging.getMetadata(imageFile, params);
// TODO only run this tests with images that have metadata...
//assertNotNull(metadata);
Debug.debug("metadata", metadata);
Debug.debug("ICC profile", Imaging.getICCProfile(imageFile, params));
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
assertNotNull(imageInfo);
try {
final BufferedImage image = Imaging.getBufferedImage(imageFile, params);
assertNotNull(image);
} catch (final ImageReadException imageReadException) {
assertEquals("Only sequential, baseline JPEGs are supported at the moment",
imageReadException.getMessage());
}
}
示例12: test
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Test
public void test() throws Exception {
Debug.debug("start");
final List<File> images = getWbmpImages();
for (final File imageFile : images) {
Debug.debug("imageFile", imageFile);
final ImageMetadata metadata = Imaging.getMetadata(imageFile);
Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null)
final Map<String, Object> params = new HashMap<>();
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
assertNotNull(imageInfo);
final BufferedImage image = Imaging.getBufferedImage(imageFile);
assertNotNull(image);
}
}
示例13: writeAndReadImageData
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
private void writeAndReadImageData(final String description, final byte[] rawData,
final int foreground, final int background) throws IOException,
ImageReadException {
// Uncomment to generate ICO files that can be tested with Windows:
// File exportFile = new File("/tmp/" + description + ".ico");
// IoUtils.writeToFile(rawData, exportFile);
final File tempFile = createTempFile("temp", ".ico");
FileUtils.writeByteArrayToFile(tempFile, rawData);
final BufferedImage dstImage = Imaging.getBufferedImage(tempFile);
assertNotNull(dstImage);
assertTrue(dstImage.getWidth() == IMAGE[0].length);
assertTrue(dstImage.getHeight() == IMAGE.length);
verify(dstImage, foreground, background);
}
示例14: test
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Test
public void test() throws Exception {
final List<File> images = getTestImages();
for (final File imageFile : images) {
if (imageFile.getName().toLowerCase().endsWith(".png")
&& isInvalidPNGTestFile(imageFile)) {
continue;
}
Debug.debug("imageFile", imageFile);
Debug.debug();
final String xmpXml = Imaging.getXmpXml(imageFile);
if (null == xmpXml) {
continue;
}
assertNotNull(xmpXml);
Debug.debug("xmpXml: " + xmpXml);
Debug.debug();
}
}
示例15: testWriteImageRaw_happyCase
import org.apache.commons.imaging.Imaging; //导入依赖的package包/类
@Test
public void testWriteImageRaw_happyCase() throws ImageWriteException,
ImageReadException, IOException {
BufferedImage srcImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
final Map<String, Object> params = new HashMap<>();
params.put(PnmImageParser.PARAM_KEY_PNM_RAWBITS, PnmImageParser.PARAM_VALUE_PNM_RAWBITS_YES);
final byte[] dstBytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNM, params);
final BufferedImage dstImage = Imaging.getBufferedImage(dstBytes);
assertTrue(srcImage.getWidth() == dstImage.getWidth());
assertTrue(srcImage.getHeight() == dstImage.getHeight());
DataBufferInt srcData = (DataBufferInt) srcImage.getRaster().getDataBuffer();
DataBufferInt dstData = (DataBufferInt) dstImage.getRaster().getDataBuffer();
for (int bank = 0; bank < srcData.getNumBanks(); bank++) {
int[] actual = srcData.getData(bank);
int[] expected = dstData.getData(bank);
assertArrayEquals(actual, expected);
}
}