40package com.jogamp.opengl.util.awt;
43import java.awt.image.*;
54 final WritableRaster raster = image.getRaster();
55 Object scanline1 =
null;
56 Object scanline2 =
null;
58 for (
int i = 0; i < image.getHeight() / 2; i++) {
59 scanline1 = raster.getDataElements(0, i, image.getWidth(), 1, scanline1);
60 scanline2 = raster.getDataElements(0, image.getHeight() - i - 1, image.getWidth(), 1, scanline2);
61 raster.setDataElements(0, i, image.getWidth(), 1, scanline2);
62 raster.setDataElements(0, image.getHeight() - i - 1, image.getWidth(), 1, scanline1);
77 final GraphicsConfiguration configuration =
78 GraphicsEnvironment.getLocalGraphicsEnvironment().
79 getDefaultScreenDevice().getDefaultConfiguration();
80 return configuration.createCompatibleImage(width, height);
95 public static BufferedImage
createThumbnail(
final BufferedImage image,
final int thumbWidth) {
97 if (thumbWidth > image.getWidth()) {
98 throw new IllegalArgumentException(
"Thumbnail width must be greater than image width");
101 if (thumbWidth == image.getWidth()) {
105 final float ratio = (float) image.getWidth() / (float) image.getHeight();
106 int width = image.getWidth();
107 BufferedImage thumb = image;
111 if (width < thumbWidth) {
116 final Graphics2D g2 = temp.createGraphics();
117 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
118 RenderingHints.VALUE_INTERPOLATION_BILINEAR);
119 g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(),
null);
122 }
while (width != thumbWidth);
Utilities for dealing with images.
static BufferedImage createCompatibleImage(final int width, final int height)
Creates a BufferedImage with a pixel format compatible with the graphics environment.
static void flipImageVertically(final BufferedImage image)
Flips the supplied BufferedImage vertically.
static BufferedImage createThumbnail(final BufferedImage image, final int thumbWidth)
Creates a thumbnail from an image.