List of usage examples for org.apache.commons.imaging ImageReadException printStackTrace
public void printStackTrace()
From source file:de.tehame.examples.MetadataExample.java
public static void main(String[] args) { System.out.println("GIO"); try {//from www. j a va2 s. c o m MetadataExample metadataExample = new MetadataExample(); metadataExample.metadataExample(new File("bild1.jpg")); } catch (ImageReadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.hygenics.imaging.ImageCleanup.java
/** * Set the image type to jpg//from w ww . j a v a 2s. c o m */ public void setImageType(String inurl, byte[] ibytes) { String imgType = null; String urltst = inurl; // get the image type from the url if (inurl != null) { urltst = inurl.toLowerCase(); } // get the image type from the url which should contain the MIME type if (!urltst.toLowerCase().contains("jpg") | !urltst.toLowerCase().contains("jpeg")) { ByteArrayInputStream bis = new ByteArrayInputStream(ibytes); if (bis != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); // convert to jpeg for compression try { // use apache to read to a buffered image with certain // metadata and then convert to a jpg BufferedImage image = Imaging.getBufferedImage(bis); ImageIO.write(image, "jpg", bos); ibytes = bos.toByteArray(); } catch (ImageReadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } imgType = "jpg"; }
From source file:com.hygenics.imaging.ImageCleanup.java
public byte[] writeMetaData(String data, byte[] ibytes) { // write metadata based on the metadata columns list TiffOutputSet outset = null;//w w w . ja v a2 s .co m BufferedImage bi; ImageMetadata metadata; ByteArrayOutputStream bos = null; try { // get the buffered image to write to bi = Imaging.getBufferedImage(ibytes); metadata = Imaging.getMetadata(ibytes); JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (null != jpegMetadata) { // get the image exif data TiffImageMetadata exif = jpegMetadata.getExif(); outset = exif.getOutputSet(); } if (outset == null) { // get a new set (directory structured to write to) outset = new TiffOutputSet(); } TiffOutputDirectory exdir = outset.getOrCreateExifDirectory(); exdir.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT); exdir.add(ExifTagConstants.EXIF_TAG_USER_COMMENT, data.trim()); bos = new ByteArrayOutputStream(); ByteArrayInputStream bis = new ByteArrayInputStream(ibytes); ExifRewriter exrw = new ExifRewriter(); // read to a byte stream exrw.updateExifMetadataLossy(bis, bos, outset); // read the input from the byte buffer ibytes = bos.toByteArray(); bis.close(); bos.close(); } catch (ImageReadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ImageWriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (bos != null) { try { bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); } } } return ibytes; }