Ejemplo n.º 1
0
  private void roundtrip(
      FormatInfo formatInfo, BufferedImage testImage, String tempPrefix, boolean imageExact)
      throws IOException, ImageReadException, ImageWriteException {
    File temp1 = createTempFile(tempPrefix + ".", "." + formatInfo.format.extension);
    // Debug.debug("tempFile: " + tempFile.getName());

    Map params = new HashMap();
    Sanselan.writeImage(testImage, temp1, formatInfo.format, params);

    Map readParams = new HashMap();
    readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY, new RgbBufferedImageFactory());
    BufferedImage image2 = Sanselan.getBufferedImage(temp1, readParams);
    assertNotNull(image2);

    if (imageExact) {
      // note tolerance when comparing grayscale images
      // BufferedImages of
      compareImagesExact(testImage, image2);
    }

    File temp2 = createTempFile(tempPrefix + ".", "." + formatInfo.format.extension);
    // Debug.debug("tempFile: " + tempFile.getName());
    Sanselan.writeImage(image2, temp2, formatInfo.format, params);

    compareFilesExact(temp1, temp2);
  }
Ejemplo n.º 2
0
 /**
  * translate a binary array to a buffered image
  *
  * @param binary
  * @return
  * @throws IOException
  */
 @Override
 public final BufferedImage toBufferedImage(byte[] bytes, String format) throws IOException {
   try {
     return Sanselan.getBufferedImage(new ByteArrayInputStream(bytes));
   } catch (ImageReadException e) {
     throw ExceptionUtil.toIOException(e);
   }
 }
Ejemplo n.º 3
0
 /**
  * translate a file resource to a buffered image
  *
  * @param res
  * @return
  * @throws IOException
  */
 @Override
 public final BufferedImage toBufferedImage(Resource res, String format) throws IOException {
   InputStream is = null;
   try {
     return Sanselan.getBufferedImage(is = res.getInputStream());
   } catch (ImageReadException e) {
     throw ExceptionUtil.toIOException(e);
   } finally {
     IOUtil.closeEL(is);
   }
 }
Ejemplo n.º 4
0
 public static BufferedImage readBmp(InputStream is) throws ImageReadException, IOException {
   return Sanselan.getBufferedImage(is);
 }