java.awt.image.BufferedImage

Here are the examples of the java api class java.awt.image.BufferedImage taken from open source projects.

1. HeadlessBufferedImage#main()

Project: openjdk
Source File: HeadlessBufferedImage.java
View license
public static void main(String args[]) {
    BufferedImage bi;
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_3BYTE_BGR);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_4BYTE_ABGR);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_BYTE_BINARY);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_BYTE_GRAY);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_BYTE_INDEXED);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB_PRE);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_BGR);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_USHORT_565_RGB);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_USHORT_GRAY);
    bi = new BufferedImage(300, 300, BufferedImage.TYPE_USHORT_555_RGB);
    bi.getType();
    bi.getColorModel();
    bi.getRaster();
    bi.getAlphaRaster();
    bi.getRGB(1, 1);
    bi.getWidth();
    bi.getHeight();
    bi.getSource();
    bi.flush();
    bi.getGraphics();
    bi.createGraphics();
    BufferedImage bi2 = bi.getSubimage(10, 10, 200, 200);
    bi.isAlphaPremultiplied();
    bi.coerceData(true);
    bi.coerceData(false);
    bi.toString();
    bi.getSources();
    bi.getPropertyNames();
    bi.getMinX();
    bi.getMinY();
    bi.getSampleModel();
    bi.getNumXTiles();
    bi.getNumYTiles();
    bi.getMinTileX();
    bi.getMinTileY();
    bi.getTileWidth();
    bi.getTileHeight();
    bi.getTileGridXOffset();
    bi.getTileGridYOffset();
    bi.getData();
}

2. TestConvertBufferedImage#stripAlphaChannel()

View license
@Test
public void stripAlphaChannel() {
    BufferedImage a = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_4BYTE_ABGR);
    BufferedImage b = ConvertBufferedImage.stripAlphaChannel(a);
    assertTrue(a != b);
    assertEquals(3, b.getRaster().getNumBands());
    BufferedImage c = ConvertBufferedImage.stripAlphaChannel(b);
    assertTrue(b == c);
    a = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_BYTE_GRAY);
    c = ConvertBufferedImage.stripAlphaChannel(a);
    assertTrue(a == c);
    a = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_3BYTE_BGR);
    c = ConvertBufferedImage.stripAlphaChannel(a);
    assertTrue(a == c);
}

3. CanvasTest#subsequentImagesCroppedCorrectly()

Project: thumbnailator
Source File: CanvasTest.java
View license
@Test
public void subsequentImagesCroppedCorrectly() {
    /*
		 * Original code was changing the width/height settings when cropping
		 * was disabled, and if the image was larger than the width/height
		 * specified for the Canvas object.
		 */
    // given
    BufferedImage img1 = new BufferedImage(120, 120, BufferedImage.TYPE_INT_ARGB);
    BufferedImage img2 = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
    ImageFilter filter = new Canvas(100, 100, Positions.CENTER, false);
    // when
    BufferedImage result1 = filter.apply(img1);
    BufferedImage result2 = filter.apply(img2);
    // then
    assertEquals(120, result1.getWidth());
    assertEquals(120, result1.getHeight());
    assertEquals(100, result2.getWidth());
    assertEquals(100, result2.getHeight());
}

4. ColConvCCMTest#testSubImage()

Project: openjdk
Source File: ColConvCCMTest.java
View license
static boolean testSubImage(int x0, int y0, int dx, int dy, int dataType, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}

5. ColConvDCMTest#testSubImage()

Project: openjdk
Source File: ColConvDCMTest.java
View license
static boolean testSubImage(int x0, int y0, int dx, int dy, int type, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}

6. ColConvCCMTest#testSubImage()

Project: jdk7u-jdk
Source File: ColConvCCMTest.java
View license
static boolean testSubImage(int x0, int y0, int dx, int dy, int dataType, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
    BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}

7. ColConvDCMTest#testSubImage()

Project: jdk7u-jdk
Source File: ColConvDCMTest.java
View license
static boolean testSubImage(int x0, int y0, int dx, int dy, int type, int rBits, int gBits, int bBits, int cs, BufferedImage gldImage, double accuracy) {
    BufferedImage src = ImageFactory.createDCMImage(type, cs);
    BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
    BufferedImage dst = ImageFactory.createDstImage(BufferedImage.TYPE_INT_RGB);
    BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(subSrc, subDst);
    ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, bBits);
    boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
    if (!result) {
        System.err.println(cmp.getStat());
    }
    return result;
}

8. WatermarkTest#inputContentsAreNotAltered()

Project: thumbnailator
Source File: WatermarkTest.java
View license
/**
	 * Checks that the input image contents are not altered.
	 */
@Test
public void inputContentsAreNotAltered() {
    // given
    BufferedImage originalImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
    BufferedImage copyImage = BufferedImages.copy(originalImage);
    BufferedImage watermarkImg = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
    ImageFilter filter = new Watermark(Positions.BOTTOM_CENTER, watermarkImg, 0.5f);
    // when
    filter.apply(originalImage);
    // then
    assertTrue(BufferedImageComparer.isSame(originalImage, copyImage));
}

9. BufferedImageSourceTest#appliesSourceRegion()

View license
/*
	 *
	 *     +------+-----------+
	 *     |XXXXXX|           |
	 *     |XXXXXX|           |
	 *     +------+           |
	 *     |      region      |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegion() throws IOException {
    // given
    BufferedImage sourceImage = ImageIO.read(new File("src/test/resources/Thumbnailator/grid.png"));
    BufferedImageSource source = new BufferedImageSource(sourceImage);
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(Positions.TOP_LEFT, new AbsoluteSize(40, 40))).size(20, 20).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 40, 40);
    assertTrue(BufferedImageComparer.isSame(expectedImg, img));
}

10. BufferedImageSourceTest#appliesSourceRegionTooBig()

View license
/*
	 *
	 *     +------------------+ source
	 *     |  +------------------+
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XX  final  XXXX|  |
	 *     |  |XX  region XXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     +--|---------------+  |
	 *        +------------------+
	 *                             region
	 */
@Test
public void appliesSourceRegionTooBig() throws IOException {
    // given
    BufferedImage sourceImage = ImageIO.read(new File("src/test/resources/Thumbnailator/grid.png"));
    BufferedImageSource source = new BufferedImageSource(sourceImage);
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(20, 20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(20, 20, 80, 80);
    assertTrue(BufferedImageComparer.isSame(expectedImg, img));
}

11. BufferedImageSourceTest#appliesSourceRegionBeyondOrigin()

View license
/*
	 *   +-----------------+
	 *   |                 |
	 *   | +---------------|--+
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXX final XXXX|  |
	 *   | |XXXX regionXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   +-----------------+  |
	 *     |                region
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegionBeyondOrigin() throws IOException {
    // given
    BufferedImage sourceImage = ImageIO.read(new File("src/test/resources/Thumbnailator/grid.png"));
    BufferedImageSource source = new BufferedImageSource(sourceImage);
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(-20, -20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 80, 80);
    assertTrue(BufferedImageComparer.isSame(expectedImg, img));
}

12. FileImageSourceTest#appliesSourceRegion()

View license
/*
	 *
	 *     +------+-----------+
	 *     |XXXXXX|           |
	 *     |XXXXXX|           |
	 *     +------+           |
	 *     |      region      |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegion() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    FileImageSource source = new FileImageSource(sourceFile);
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(Positions.TOP_LEFT, new AbsoluteSize(40, 40))).size(20, 20).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 40, 40);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

13. FileImageSourceTest#appliesSourceRegionTooBig()

View license
/*
	 *
	 *     +------------------+ source
	 *     |  +------------------+
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XX  final  XXXX|  |
	 *     |  |XX  region XXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     +--|---------------+  |
	 *        +------------------+
	 *                             region
	 */
@Test
public void appliesSourceRegionTooBig() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    FileImageSource source = new FileImageSource(sourceFile);
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(20, 20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(20, 20, 80, 80);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

14. FileImageSourceTest#appliesSourceRegionBeyondOrigin()

View license
/*
	 *   +-----------------+
	 *   |                 |
	 *   | +---------------|--+
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXX final XXXX|  |
	 *   | |XXXX regionXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   +-----------------+  |
	 *     |                region
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegionBeyondOrigin() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    FileImageSource source = new FileImageSource(sourceFile);
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(-20, -20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 80, 80);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

15. InputStreamImageSourceTest#appliesSourceRegion()

View license
/*
	 *
	 *     +------+-----------+
	 *     |XXXXXX|           |
	 *     |XXXXXX|           |
	 *     +------+           |
	 *     |      region      |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegion() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(Positions.TOP_LEFT, new AbsoluteSize(40, 40))).size(20, 20).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 40, 40);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

16. InputStreamImageSourceTest#appliesSourceRegionTooBig()

View license
/*
	 *
	 *     +------------------+ source
	 *     |  +------------------+
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XX  final  XXXX|  |
	 *     |  |XX  region XXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     +--|---------------+  |
	 *        +------------------+
	 *                             region
	 */
@Test
public void appliesSourceRegionTooBig() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(20, 20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(20, 20, 80, 80);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

17. InputStreamImageSourceTest#appliesSourceRegionBeyondOrigin()

View license
/*
	 *   +-----------------+
	 *   |                 |
	 *   | +---------------|--+
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXX final XXXX|  |
	 *   | |XXXX regionXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   +-----------------+  |
	 *     |                region
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegionBeyondOrigin() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(-20, -20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 80, 80);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

18. URLImageSourceTest#appliesSourceRegion()

View license
/*
	 *
	 *     +------+-----------+
	 *     |XXXXXX|           |
	 *     |XXXXXX|           |
	 *     +------+           |
	 *     |      region      |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     |                  |
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegion() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Thumbnailator/grid.png"));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(Positions.TOP_LEFT, new AbsoluteSize(40, 40))).size(20, 20).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 40, 40);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

19. URLImageSourceTest#appliesSourceRegionTooBig()

View license
/*
	 *
	 *     +------------------+ source
	 *     |  +------------------+
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XX  final  XXXX|  |
	 *     |  |XX  region XXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     |  |XXXXXXXXXXXXXXX|  |
	 *     +--|---------------+  |
	 *        +------------------+
	 *                             region
	 */
@Test
public void appliesSourceRegionTooBig() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Thumbnailator/grid.png"));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(20, 20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(20, 20, 80, 80);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

20. URLImageSourceTest#appliesSourceRegionBeyondOrigin()

View license
/*
	 *   +-----------------+
	 *   |                 |
	 *   | +---------------|--+
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXX final XXXX|  |
	 *   | |XXXX regionXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   | |XXXXXXXXXXXXXXX|  |
	 *   +-----------------+  |
	 *     |                region
	 *     +------------------+
	 *                        source
	 */
@Test
public void appliesSourceRegionBeyondOrigin() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Thumbnailator/grid.png"));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().region(new Region(new Coordinate(-20, -20), new AbsoluteSize(100, 100))).size(80, 80).build());
    // when
    BufferedImage img = source.read();
    // then
    BufferedImage expectedImg = sourceImage.getSubimage(0, 0, 80, 80);
    assertTrue(BufferedImageComparer.isRGBSimilar(expectedImg, img));
}

21. ThumbnailsBuilderInputOutputTest#of_BufferedImages_iterableBufferedImages_NoOutputFormatSpecified()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>Thumbnails.of(BufferedImage, BufferedImage)</li>
	 * <li>iterableBufferedImages()</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>Processing completes successfully.</li>
	 * </ol>
	 * @throws IOException
	 */
@Test
public void of_BufferedImages_iterableBufferedImages_NoOutputFormatSpecified() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    Iterable<BufferedImage> thumbnails = Thumbnails.of(img, img).size(50, 50).iterableBufferedImages();
    // then
    Iterator<BufferedImage> iter = thumbnails.iterator();
    BufferedImage thumbnail1 = iter.next();
    assertEquals(50, thumbnail1.getWidth());
    assertEquals(50, thumbnail1.getHeight());
    BufferedImage thumbnail2 = iter.next();
    assertEquals(50, thumbnail2.getWidth());
    assertEquals(50, thumbnail2.getHeight());
    assertFalse(iter.hasNext());
}

22. GraphicsUtils#loadDoubleFilterImage()

Project: LGame
Source File: GraphicsUtils.java
View license
/**
	 * ??????????
	 * 
	 * @param img
	 * @param width
	 * @param height
	 * @return
	 */
public static final BufferedImage loadDoubleFilterImage(final Image img, final int width, final int height) {
    BufferedImage img1 = GraphicsUtils.drawClipImage(img, width, height, 0, 0);
    BufferedImage img2 = GraphicsUtils.drawClipImage(img, width, height, width, 0);
    WritableRaster writableRaster1 = img1.getRaster();
    DataBuffer dataBuffer1 = writableRaster1.getDataBuffer();
    int[] basePixels1 = AWTDataBufferHelper.getDataInt(dataBuffer1);
    WritableRaster writableRaster2 = img2.getRaster();
    DataBuffer dataBuffer2 = writableRaster2.getDataBuffer();
    int[] basePixels2 = AWTDataBufferHelper.getDataInt(dataBuffer2);
    int length = basePixels2.length;
    for (int i = 0; i < length; i++) {
        if (basePixels2[i] >= LColor.getRGB(200, 200, 200)) {
            basePixels2[i] = 0xffffff;
        } else {
            basePixels2[i] = basePixels1[i];
        }
    }
    img1.flush();
    img1 = null;
    return img2;
}

23. Rainbow4JTest#shouldApply_maskFilter_andShouldGive_biggerDifference()

Project: galen
Source File: Rainbow4JTest.java
View license
@Test
public void shouldApply_maskFilter_andShouldGive_biggerDifference() throws IOException {
    BufferedImage imageActual = Rainbow4J.loadImage(getClass().getResourceAsStream("/mask/actual.png"));
    BufferedImage imageExpected = Rainbow4J.loadImage(getClass().getResourceAsStream("/mask/expected-with-rect-and-cross.png"));
    BufferedImage imageMask = Rainbow4J.loadImage(getClass().getResourceAsStream("/mask/mask.png"));
    ComparisonOptions options = new ComparisonOptions();
    List<ImageFilter> filters = new LinkedList<>();
    filters.add(new MaskFilter(new ImageHandler(imageMask)));
    options.setOriginalFilters(filters);
    ImageCompareResult result = Rainbow4J.compare(imageActual, imageExpected, options);
    assertThat(result.getTotalPixels(), is(7907L));
    assertThat(result.getPercentage(), is(lessThan(30.0)));
    assertThat(result.getPercentage(), is(greaterThan(28.0)));
}

24. MlibOpsTest#doTest()

Project: jdk7u-jdk
Source File: MlibOpsTest.java
View license
public static void doTest(BufferedImageOp op) {
    BufferedImage src = createSrcImage();
    BufferedImage dst = createImage();
    BufferedImage ret = null;
    try {
        ret = ImagingLib.filter(op, src, dst);
    } catch (Exception e) {
        throw new RuntimeException("Test FAILED.", e);
    }
    if (ret == null) {
        throw new RuntimeException("Test FAILED: null output");
    }
    System.out.println("ret: " + ret);
    System.out.println("Test PASSED for " + op.getClass().getName());
}

25. MlibOpsTest#doTest()

Project: openjdk
Source File: MlibOpsTest.java
View license
public static void doTest(BufferedImageOp op) {
    BufferedImage src = createSrcImage();
    BufferedImage dst = createImage();
    BufferedImage ret = null;
    try {
        ret = ImagingLib.filter(op, src, dst);
    } catch (Exception e) {
        throw new RuntimeException("Test FAILED.", e);
    }
    if (ret == null) {
        throw new RuntimeException("Test FAILED: null output");
    }
    System.out.println("ret: " + ret);
    System.out.println("Test PASSED for " + op.getClass().getName());
}

26. CannyEdgeDetectorTest#testComic()

Project: LIRE
Source File: CannyEdgeDetectorTest.java
View license
public void testComic() throws IOException {
    BufferedImage in = ImageIO.read(new File("flower.jpg"));
    CannyEdgeDetector ced = new CannyEdgeDetector(in, 30, 80);
    BufferedImage filter = ced.filter();
    BufferedImage flower = PixelClustering.clusterPixels(in);
    WritableRaster raster = flower.getRaster();
    Graphics graphics = flower.getGraphics();
    graphics.setColor(Color.black);
    int[] tmp = new int[3];
    for (int x = 0; x < raster.getWidth(); x++) {
        for (int y = 0; y < raster.getHeight(); y++) {
            filter.getRaster().getPixel(x, y, tmp);
            if (tmp[0] < 10) {
                graphics.fillOval(x, y, 3, 4);
            }
        }
    }
    ImageIO.write(filter, "png", new File("flower-canny.png"));
    ImageIO.write(flower, "png", new File("flower-comic.png"));
}

27. VisualizeAverageDownSample#main()

View license
public static void main(String[] args) {
    BufferedImage original = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg"));
    Planar<GrayF32> input = new Planar<GrayF32>(GrayF32.class, original.getWidth(), original.getHeight(), 3);
    ConvertBufferedImage.convertFromMulti(original, input, true, GrayF32.class);
    Planar<GrayF32> output = new Planar<GrayF32>(GrayF32.class, original.getWidth() / 3, original.getHeight() / 3, 3);
    Planar<GrayF32> output2 = new Planar<GrayF32>(GrayF32.class, original.getWidth() / 3, original.getHeight() / 3, 3);
    AverageDownSampleOps.down(input, output);
    new FDistort(input, output2).scaleExt().apply();
    BufferedImage outputFull = ConvertBufferedImage.convertTo_F32(output, null, true);
    BufferedImage outputFull2 = ConvertBufferedImage.convertTo_F32(output2, null, true);
    ShowImages.showWindow(original, "Original");
    ShowImages.showWindow(outputFull, "3x small average");
    ShowImages.showWindow(outputFull2, "3x small bilinear");
}

28. Rainbow4JTest#shouldApply_maskFilter_andShouldGive_smallDifference()

Project: galen
Source File: Rainbow4JTest.java
View license
@Test
public void shouldApply_maskFilter_andShouldGive_smallDifference() throws IOException {
    BufferedImage imageActual = Rainbow4J.loadImage(getClass().getResourceAsStream("/mask/actual.png"));
    BufferedImage imageExpected = Rainbow4J.loadImage(getClass().getResourceAsStream("/mask/expected-with-rect.png"));
    BufferedImage imageMask = Rainbow4J.loadImage(getClass().getResourceAsStream("/mask/mask.png"));
    ComparisonOptions options = new ComparisonOptions();
    List<ImageFilter> filters = new LinkedList<>();
    filters.add(new MaskFilter(new ImageHandler(imageMask)));
    options.setOriginalFilters(filters);
    ImageCompareResult result = Rainbow4J.compare(imageActual, imageExpected, options);
    assertThat(result.getTotalPixels(), is(57L));
    assertThat(result.getPercentage(), is(lessThan(0.25)));
}

29. InputStreamImageSourceTest#readImageUnaffectedForOrientation1()

View license
@Test
public void readImageUnaffectedForOrientation1() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_1.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

30. ExampleRemovePerspectiveDistortion#main()

View license
public static void main(String[] args) {
    // load a color image
    BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("goals_and_stuff.jpg"));
    Planar<GrayF32> input = ConvertBufferedImage.convertFromMulti(buffered, null, true, GrayF32.class);
    RemovePerspectiveDistortion<Planar<GrayF32>> removePerspective = new RemovePerspectiveDistortion<Planar<GrayF32>>(400, 500, ImageType.pl(3, GrayF32.class));
    // Order matters! top-left, top-right, bottom-right, bottom-left
    if (!removePerspective.apply(input, new Point2D_F64(267, 182), new Point2D_F64(542, 68), new Point2D_F64(519, 736), new Point2D_F64(276, 570))) {
        throw new RuntimeException("Failed!?!?");
    }
    Planar<GrayF32> output = removePerspective.getOutput();
    BufferedImage flat = ConvertBufferedImage.convertTo_F32(output, null, true);
    ShowImages.showWindow(buffered, "Original Image", true);
    ShowImages.showWindow(flat, "Without Perspective Distortion", true);
}

31. InputStreamImageSourceTest#readImageUnaffectedForOrientation2()

View license
@Test
public void readImageUnaffectedForOrientation2() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_2.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

32. InputStreamImageSourceTest#readImageUnaffectedForOrientation3()

View license
@Test
public void readImageUnaffectedForOrientation3() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_3.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

33. InputStreamImageSourceTest#readImageUnaffectedForOrientation4()

View license
@Test
public void readImageUnaffectedForOrientation4() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_4.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

34. InputStreamImageSourceTest#readImageUnaffectedForOrientation5()

View license
@Test
public void readImageUnaffectedForOrientation5() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_5.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

35. InputStreamImageSourceTest#readImageUnaffectedForOrientation6()

View license
@Test
public void readImageUnaffectedForOrientation6() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_6.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

36. InputStreamImageSourceTest#readImageUnaffectedForOrientation7()

View license
@Test
public void readImageUnaffectedForOrientation7() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_7.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

37. InputStreamImageSourceTest#readImageUnaffectedForOrientation8()

View license
@Test
public void readImageUnaffectedForOrientation8() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_8.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    InputStreamImageSource source = new InputStreamImageSource(new FileInputStream(sourceFile));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

38. OutputStreamImageSinkTest#write_ValidImage_SetOutputFormat()

View license
@Test
public void write_ValidImage_SetOutputFormat() throws IOException {
    // given
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    BufferedImage imgToWrite = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
    OutputStreamImageSink sink = new OutputStreamImageSink(os);
    // when
    sink.setOutputFormatName("png");
    sink.write(imgToWrite);
    // then
    assertEquals(os, sink.getSink());
    byte[] imageData = os.toByteArray();
    BufferedImage writtenImg = ImageIO.read(new ByteArrayInputStream(imageData));
    assertTrue(BufferedImageComparer.isRGBSimilar(imgToWrite, writtenImg));
    String formatName = TestUtils.getFormatName(new ByteArrayInputStream(imageData));
    assertEquals("png", formatName);
}

39. URLImageSourceTest#appliesSourceRegionNotSpecified()

View license
@Test
public void appliesSourceRegionNotSpecified() throws IOException {
    // given
    File sourceFile = new File("src/test/resources/Thumbnailator/grid.png");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Thumbnailator/grid.png"));
    source.setThumbnailParameter(new ThumbnailParameterBuilder().size(20, 20).build());
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

40. URLImageSourceTest#readImageUnaffectedForOrientation1()

View license
@Test
public void readImageUnaffectedForOrientation1() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_1.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_1.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

41. URLImageSourceTest#readImageUnaffectedForOrientation2()

View license
@Test
public void readImageUnaffectedForOrientation2() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_2.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_2.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

42. URLImageSourceTest#readImageUnaffectedForOrientation3()

View license
@Test
public void readImageUnaffectedForOrientation3() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_3.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_3.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

43. URLImageSourceTest#readImageUnaffectedForOrientation4()

View license
@Test
public void readImageUnaffectedForOrientation4() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_4.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_4.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

44. URLImageSourceTest#readImageUnaffectedForOrientation5()

View license
@Test
public void readImageUnaffectedForOrientation5() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_5.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_5.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

45. URLImageSourceTest#readImageUnaffectedForOrientation6()

View license
@Test
public void readImageUnaffectedForOrientation6() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_6.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_6.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

46. URLImageSourceTest#readImageUnaffectedForOrientation7()

View license
@Test
public void readImageUnaffectedForOrientation7() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_7.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_7.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

47. URLImageSourceTest#readImageUnaffectedForOrientation8()

View license
@Test
public void readImageUnaffectedForOrientation8() throws Exception {
    // given
    File sourceFile = new File("src/test/resources/Exif/source_8.jpg");
    BufferedImage sourceImage = ImageIO.read(sourceFile);
    URLImageSource source = new URLImageSource(new URL("file:src/test/resources/Exif/source_8.jpg"));
    ThumbnailParameter param = new ThumbnailParameterBuilder().size(20, 20).build();
    source.setThumbnailParameter(param);
    // when
    BufferedImage img = source.read();
    // then
    assertTrue(BufferedImageComparer.isRGBSimilar(sourceImage, img));
}

48. FormatRed#copyData()

Project: xml-graphics-commons
Source File: FormatRed.java
View license
public WritableRaster copyData(WritableRaster wr) {
    ColorModel cm = getColorModel();
    CachableRed cr = getSource();
    ColorModel srcCM = cr.getColorModel();
    SampleModel srcSM = cr.getSampleModel();
    srcSM = srcSM.createCompatibleSampleModel(wr.getWidth(), wr.getHeight());
    WritableRaster srcWR;
    srcWR = Raster.createWritableRaster(srcSM, new Point(wr.getMinX(), wr.getMinY()));
    getSource().copyData(srcWR);
    BufferedImage srcBI = new BufferedImage(srcCM, srcWR.createWritableTranslatedChild(0, 0), srcCM.isAlphaPremultiplied(), null);
    BufferedImage dstBI = new BufferedImage(cm, wr.createWritableTranslatedChild(0, 0), cm.isAlphaPremultiplied(), null);
    GraphicsUtil.copyData(srcBI, dstBI);
    return wr;
}

49. ImageEncodingHelperTestCase#testRGBAndBGRImages()

View license
/**
     * Tests a BGR versus RBG image. Debugging shows the BGR follows the optimizeWriteTo() (which
     * is intended). The bytes are compared with the RBG image, which happens to follow the
     * writeRGBTo().
     *
     * @throws IOException
     */
@Test
public void testRGBAndBGRImages() throws IOException {
    BufferedImage imageBGR = new BufferedImage(100, 75, BufferedImage.TYPE_3BYTE_BGR);
    imageBGR = prepareImage(imageBGR);
    BufferedImage imageRGB = new BufferedImage(100, 75, BufferedImage.TYPE_INT_BGR);
    imageRGB = prepareImage(imageRGB);
    ImageEncodingHelper imageEncodingHelperBGR = new ImageEncodingHelper(imageBGR, false);
    ImageEncodingHelper imageEncodingHelperRGB = new ImageEncodingHelper(imageRGB, false);
    ByteArrayOutputStream baosBGR = new ByteArrayOutputStream();
    imageEncodingHelperBGR.encode(baosBGR);
    ByteArrayOutputStream baosRGB = new ByteArrayOutputStream();
    imageEncodingHelperRGB.encode(baosRGB);
    assertTrue(Arrays.equals(baosBGR.toByteArray(), baosRGB.toByteArray()));
}

50. DecodeWorker#writeResultImage()

Project: zxing
Source File: DecodeWorker.java
View license
private static void writeResultImage(int stride, int height, int[] pixels, URI input, String suffix) throws IOException {
    BufferedImage result = new BufferedImage(stride, height, BufferedImage.TYPE_INT_ARGB);
    result.setRGB(0, 0, stride, height, pixels, 0, stride);
    Path imagePath = buildOutputPath(input, suffix);
    try {
        if (!ImageIO.write(result, "png", imagePath.toFile())) {
            System.err.println("Could not encode an image to " + imagePath);
        }
    } catch (IOException ignored) {
        System.err.println("Could not write to " + imagePath);
    }
}

51. MatrixToImageWriter#toBufferedImage()

Project: zxing
Source File: MatrixToImageWriter.java
View license
/**
   * As {@link #toBufferedImage(BitMatrix)}, but allows customization of the output.
   *
   * @param matrix {@link BitMatrix} to write
   * @param config output configuration
   * @return {@link BufferedImage} representation of the input
   */
public static BufferedImage toBufferedImage(BitMatrix matrix, MatrixToImageConfig config) {
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    BufferedImage image = new BufferedImage(width, height, config.getBufferedImageColorModel());
    int onColor = config.getPixelOnColor();
    int offColor = config.getPixelOffColor();
    int[] pixels = new int[width * height];
    int index = 0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            pixels[index++] = matrix.get(x, y) ? onColor : offColor;
        }
    }
    image.setRGB(0, 0, width, height, pixels, 0, width);
    return image;
}

52. ThumbnailsBuilderTest#resizerThenAlphainterpolation()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The resizer method is called.</li>
	 * <li>Then, the alphaInterpolation method is called.</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>A thumbnail is created successfully.</li>
	 * </ol>
	 */
@Test
public void resizerThenAlphainterpolation() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(50, 50).resizer(Resizers.PROGRESSIVE).alphaInterpolation(AlphaInterpolation.SPEED).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

53. ThumbnailsBuilderTest#resizerThenDithering()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The resizer method is called.</li>
	 * <li>Then, the dithering method is called.</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>A thumbnail is created successfully.</li>
	 * </ol>
	 */
@Test
public void resizerThenDithering() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(50, 50).resizer(Resizers.PROGRESSIVE).dithering(Dithering.DEFAULT).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

54. ThumbnailsBuilderTest#resizerThenAntialiasing()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The resizer method is called.</li>
	 * <li>Then, the antialiasing method is called.</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>A thumbnail is created successfully.</li>
	 * </ol>
	 */
@Test
public void resizerThenAntialiasing() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(50, 50).resizer(Resizers.PROGRESSIVE).antialiasing(Antialiasing.DEFAULT).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

55. ThumbnailsBuilderTest#resizerThenRendering()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The resizer method is called.</li>
	 * <li>Then, the rendering method is called.</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>A thumbnail is created successfully.</li>
	 * </ol>
	 */
@Test
public void resizerThenRendering() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(50, 50).resizer(Resizers.PROGRESSIVE).rendering(Rendering.DEFAULT).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

56. ThumbnailsBuilderTest#width()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The width method is called</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void width() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).width(50).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(25, thumbnail.getHeight());
}

57. ThumbnailsBuilderTest#height()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The height method is called</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void height() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).height(50).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

58. ThumbnailsBuilderTest#widthAndHeight()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The width method is called</li>
	 * <li>The height method is called</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size is constrained by the height</li>
	 * <li>The image is constrained to the smallest dimension</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void widthAndHeight() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).width(50).height(50).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(25, thumbnail.getHeight());
}

59. ThumbnailsBuilderTest#heightAndWidth()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The height method is called</li>
	 * <li>The width method is called</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size is constrained by the height</li>
	 * <li>The image is constrained to the smallest dimension</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void heightAndWidth() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).height(50).width(50).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(25, thumbnail.getHeight());
}

60. ThumbnailsBuilderTest#widthAndPreservingTheAspectRatio()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The width method is called</li>
	 * <li>The keepAspectRatio is called with true</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void widthAndPreservingTheAspectRatio() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).width(50).keepAspectRatio(true).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(25, thumbnail.getHeight());
}

61. ThumbnailsBuilderTest#heightAndPreservingTheAspectRatio()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The height method is called</li>
	 * <li>The keepAspectRatio is called with true</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void heightAndPreservingTheAspectRatio() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).height(50).keepAspectRatio(true).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

62. ThumbnailsBuilderTest#widthAndHeightAndPreservingTheAspectRatio()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The width method is called</li>
	 * <li>The height method is called</li>
	 * <li>The keepAspectRatio is called with true</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size is constrained by the height</li>
	 * <li>The image is constrained to the smallest dimension</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void widthAndHeightAndPreservingTheAspectRatio() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).width(50).height(50).keepAspectRatio(true).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(25, thumbnail.getHeight());
}

63. ThumbnailsBuilderTest#heightAndWidthAndPreservingTheAspectRatio()

View license
/**
	 * Test for the {@link Thumbnails.Builder} class where,
	 * <ol>
	 * <li>The height method is called</li>
	 * <li>The width method is called</li>
	 * <li>The keepAspectRatio is called with true</li>
	 * </ol>
	 * and the expected outcome is,
	 * <ol>
	 * <li>The thumbnail size is constrained by the width</li>
	 * <li>The thumbnail size is constrained by the height</li>
	 * <li>The image is constrained to the smallest dimension</li>
	 * <li>The thumbnail size maintains the aspect ratio of the original</li>
	 * </ol>
	 */
@Test
public void heightAndWidthAndPreservingTheAspectRatio() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 100).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).height(50).width(50).keepAspectRatio(true).asBufferedImage();
    // then
    assertEquals(50, thumbnail.getWidth());
    assertEquals(25, thumbnail.getHeight());
}

64. ThumbnailsBuilderTest#cropWithSizeBefore()

View license
@Test
public void cropWithSizeBefore() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(100, 50).crop(Positions.CENTER).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

65. ThumbnailsBuilderTest#cropWithSizeAfter()

View license
@Test
public void cropWithSizeAfter() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).crop(Positions.CENTER).size(100, 50).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

66. ThumbnailsBuilderTest#cropWithAspectRatioTrueBefore()

View license
@Test
public void cropWithAspectRatioTrueBefore() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(100, 50).keepAspectRatio(true).crop(Positions.CENTER).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

67. ThumbnailsBuilderTest#cropWithAspectRatioTrueAfter()

View license
@Test
public void cropWithAspectRatioTrueAfter() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).crop(Positions.CENTER).size(100, 50).keepAspectRatio(true).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

68. ThumbnailsBuilderTest#cropWithAspectRatioFalseBefore()

View license
@Test
public void cropWithAspectRatioFalseBefore() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).size(100, 50).keepAspectRatio(false).crop(Positions.CENTER).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

69. ThumbnailsBuilderTest#cropWithAspectRatioFalseAfter()

View license
@Test
public void cropWithAspectRatioFalseAfter() throws IOException {
    // given
    BufferedImage img = new BufferedImageBuilder(200, 200).build();
    // when
    BufferedImage thumbnail = Thumbnails.of(img).crop(Positions.CENTER).size(100, 50).keepAspectRatio(false).asBufferedImage();
    // then
    assertEquals(100, thumbnail.getWidth());
    assertEquals(50, thumbnail.getHeight());
}

70. ThumbnailsBuilderTest#watermarkExifOrientation1File()

View license
@Test
public void watermarkExifOrientation1File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_1.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

71. ThumbnailsBuilderTest#watermarkExifOrientation2File()

View license
@Test
public void watermarkExifOrientation2File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_2.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

72. ThumbnailsBuilderTest#watermarkExifOrientation3File()

View license
@Test
public void watermarkExifOrientation3File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_3.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

73. ThumbnailsBuilderTest#watermarkExifOrientation4File()

View license
@Test
public void watermarkExifOrientation4File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_4.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

74. ThumbnailsBuilderTest#watermarkExifOrientation5File()

View license
@Test
public void watermarkExifOrientation5File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_5.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

75. ThumbnailsBuilderTest#watermarkExifOrientation6File()

View license
@Test
public void watermarkExifOrientation6File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_6.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

76. ThumbnailsBuilderTest#watermarkExifOrientation7File()

View license
@Test
public void watermarkExifOrientation7File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_7.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

77. ThumbnailsBuilderTest#watermarkExifOrientation8File()

View license
@Test
public void watermarkExifOrientation8File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_8.jpg";
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

78. ThumbnailsBuilderTest#watermarkExifOrientation1InputStream()

View license
@Test
public void watermarkExifOrientation1InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_1.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

79. ThumbnailsBuilderTest#watermarkExifOrientation2InputStream()

View license
@Test
public void watermarkExifOrientation2InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_2.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

80. ThumbnailsBuilderTest#watermarkExifOrientation3InputStream()

View license
@Test
public void watermarkExifOrientation3InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_3.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

81. ThumbnailsBuilderTest#watermarkExifOrientation4InputStream()

View license
@Test
public void watermarkExifOrientation4InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_4.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

82. ThumbnailsBuilderTest#watermarkExifOrientation5InputStream()

View license
@Test
public void watermarkExifOrientation5InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_5.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

83. ThumbnailsBuilderTest#watermarkExifOrientation6InputStream()

View license
@Test
public void watermarkExifOrientation6InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_6.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

84. ThumbnailsBuilderTest#watermarkExifOrientation7InputStream()

View license
@Test
public void watermarkExifOrientation7InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_7.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

85. ThumbnailsBuilderTest#watermarkExifOrientation8InputStream()

View license
@Test
public void watermarkExifOrientation8InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_8.jpg");
    BufferedImage watermark = new BufferedImageBuilder(25, 25).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(100, 100).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(99, 99));
}

86. ThumbnailsBuilderTest#watermarkAndCropExifOrientation1File()

View license
@Test
public void watermarkAndCropExifOrientation1File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_1.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

87. ThumbnailsBuilderTest#watermarkAndCropExifOrientation2File()

View license
@Test
public void watermarkAndCropExifOrientation2File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_2.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

88. ThumbnailsBuilderTest#watermarkAndCropExifOrientation3File()

View license
@Test
public void watermarkAndCropExifOrientation3File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_3.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

89. ThumbnailsBuilderTest#watermarkAndCropExifOrientation4File()

View license
@Test
public void watermarkAndCropExifOrientation4File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_4.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

90. ThumbnailsBuilderTest#watermarkAndCropExifOrientation5File()

View license
@Test
public void watermarkAndCropExifOrientation5File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_5.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

91. ThumbnailsBuilderTest#watermarkAndCropExifOrientation6File()

View license
@Test
public void watermarkAndCropExifOrientation6File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_6.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

92. ThumbnailsBuilderTest#watermarkAndCropExifOrientation7File()

View license
@Test
public void watermarkAndCropExifOrientation7File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_7.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

93. ThumbnailsBuilderTest#watermarkAndCropExifOrientation8File()

View license
@Test
public void watermarkAndCropExifOrientation8File() throws IOException {
    // given
    String imgPath = "src/test/resources/Exif/source_8.jpg";
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgPath).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

94. ThumbnailsBuilderTest#watermarkAndCropExifOrientation1InputStream()

View license
@Test
public void watermarkAndCropExifOrientation1InputStream() throws IOException {
    // given
    InputStream imgIS = new FileInputStream("src/test/resources/Exif/source_1.jpg");
    BufferedImage watermark = new BufferedImageBuilder(10, 10).build();
    Graphics g = watermark.getGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, watermark.getWidth(), watermark.getHeight());
    g.dispose();
    // when
    BufferedImage thumbnail = Thumbnails.of(imgIS).size(50, 100).crop(Positions.CENTER).watermark(Positions.BOTTOM_RIGHT, watermark, 1.0f).asBufferedImage();
    // then
    assertEquals(Color.blue.getRGB(), thumbnail.getRGB(49, 99));
}

95. AbstractGraphics2DAdapter#createGrayBufferedImageWithAlpha()

Project: fop
Source File: AbstractGraphics2DAdapter.java
View license
private static BufferedImage createGrayBufferedImageWithAlpha(int width, int height) {
    BufferedImage bi;
    boolean alphaPremultiplied = true;
    int bands = 2;
    int[] bits = new int[bands];
    for (int i = 0; i < bands; i++) {
        bits[i] = 8;
    }
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), bits, true, alphaPremultiplied, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    WritableRaster wr = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, bands, new Point(0, 0));
    bi = new BufferedImage(cm, wr, alphaPremultiplied, null);
    return bi;
}

96. IconUtil#flip()

Project: consulo
Source File: IconUtil.java
View license
@NotNull
public static Icon flip(@NotNull Icon icon, boolean horizontal) {
    int w = icon.getIconWidth();
    int h = icon.getIconHeight();
    BufferedImage first = UIUtil.createImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = first.createGraphics();
    icon.paintIcon(new JPanel(), g, 0, 0);
    g.dispose();
    BufferedImage second = UIUtil.createImage(w, h, BufferedImage.TYPE_INT_ARGB);
    g = second.createGraphics();
    if (horizontal) {
        g.drawImage(first, 0, 0, w, h, w, 0, 0, h, null);
    } else {
        g.drawImage(first, 0, 0, w, h, 0, h, w, 0, null);
    }
    g.dispose();
    return new ImageIcon(second);
}

97. IconUtil#colorize()

Project: consulo
Source File: IconUtil.java
View license
@NotNull
public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) {
    float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
    final BufferedImage image = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    final Graphics2D g = image.createGraphics();
    source.paintIcon(null, g, 0, 0);
    g.dispose();
    final BufferedImage img = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    int[] rgba = new int[4];
    float[] hsb = new float[3];
    for (int y = 0; y < image.getRaster().getHeight(); y++) {
        for (int x = 0; x < image.getRaster().getWidth(); x++) {
            image.getRaster().getPixel(x, y, rgba);
            if (rgba[3] != 0) {
                Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb);
                int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]);
                img.getRaster().setPixel(x, y, new int[] { rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3] });
            }
        }
    }
    return createImageIcon(img);
}

98. ShadowBorderPainter#createShadow()

Project: consulo
Source File: ShadowBorderPainter.java
View license
public static Shadow createShadow(Image source, int x, int y, boolean paintSource, int shadowSize) {
    int size = shadowSize;
    final float w = source.getWidth(null);
    final float h = source.getHeight(null);
    float ratio = w / h;
    float deltaX = size;
    float deltaY = size / ratio;
    final Image scaled = source.getScaledInstance((int) (w + deltaX), (int) (h + deltaY), Image.SCALE_SMOOTH);
    final BufferedImage s = GraphicsUtilities.createCompatibleTranslucentImage(scaled.getWidth(null), scaled.getHeight(null));
    final Graphics2D graphics = (Graphics2D) s.getGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.drawImage(scaled, 0, 0, null);
    final BufferedImage shadow = new ShadowRenderer(size, .25f, Color.black).createShadow(s);
    if (paintSource) {
        final Graphics imgG = shadow.getGraphics();
        final double d = size * 0.5;
        imgG.drawImage(source, (int) (size + d), (int) (size + d / ratio), null);
    }
    return new Shadow(shadow, x - size - 5, y - size + 2);
}

99. ShadowMaker#processImage()

Project: diablo-js
Source File: ShadowMaker.java
View license
public static void processImage(String in, String out) throws IOException {
    File imageFile = new File(in);
    BufferedImage bufferedImage = ImageIO.read(imageFile);
    int width = bufferedImage.getWidth(null);
    int height = bufferedImage.getHeight(null);
    BufferedImage alphaImage = new BufferedImage((width + (height / 2)), height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = alphaImage.createGraphics();
    g2d.drawImage(bufferedImage, (height / 2), 0, null);
    g2d.dispose();
    makeShadow(alphaImage);
    ImageIO.write(alphaImage, "png", new File(out));
}

100. Rainbow4JTest#shouldSave_imageAsPng()

Project: galen
Source File: Rainbow4JTest.java
View license
@Test
public void shouldSave_imageAsPng() throws IOException {
    BufferedImage image = Rainbow4J.loadImage(getClass().getResource("/test-spectrum-black-white-1.png").getFile());
    File file = File.createTempFile("test-rainbow4j-image", ".png");
    Rainbow4J.saveImage(image, file);
    assertThat("File should exist", file.exists());
    BufferedImage image2 = Rainbow4J.loadImage(file.getAbsolutePath());
    assertThat("Width should be same as original width", image2.getWidth(), is(image.getWidth()));
    assertThat("Height should be same as original height", image2.getHeight(), is(image.getHeight()));
}