* Add new Image constructor that takes a java.io.InputStream as argument.

* Always use javax.imageio.* to create new images instead of java.awt.Toolkit.
This commit is contained in:
hns 2007-06-01 09:04:17 +00:00
parent 40d0f45ba2
commit b659294a89
4 changed files with 44 additions and 56 deletions

View file

@ -18,10 +18,10 @@ package helma.image;
import helma.main.Server; import helma.main.Server;
import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.*; import java.awt.image.*;
import java.io.IOException; import java.io.*;
import java.io.OutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -136,6 +136,18 @@ public abstract class ImageGenerator {
return img != null ? new ImageWrapper(img, this) : null; return img != null ? new ImageWrapper(img, this) : null;
} }
/**
* @param input ...
* @return ...
* @throws IOException
*/
public ImageWrapper createImage(InputStream input)
throws IOException {
Image img = read(input);
return img != null ? new ImageWrapper(img, this) : null;
}
/** /**
* @param iw ... * @param iw ...
* @param filter ... * @param filter ...
@ -167,38 +179,42 @@ public abstract class ImageGenerator {
/** /**
* @param filename the filename of the image to create * @param filename the filename of the image to create
* *
* @return the newly created image * @return the newly created image
* @throws IOException * @throws IOException
*/ */
public Image read(String filename) throws IOException { public Image read(String filename) throws IOException {
return ImageWaiter.waitForImage( return ImageIO.read(new File(filename));
Toolkit.getDefaultToolkit().createImage(filename)
);
} }
/** /**
* @param url the URL of the image to create * @param url the URL of the image to create
* *
* @return the newly created image * @return the newly created image
* @throws IOException * @throws IOException
*/ */
public Image read(URL url) throws IOException { public Image read(URL url) throws IOException {
return ImageWaiter.waitForImage( return ImageIO.read(url);
Toolkit.getDefaultToolkit().createImage(url)
);
} }
/** /**
* @param src the data of the image to create * @param src the data of the image to create
* *
* @return the newly created image * @return the newly created image
* @throws IOException * @throws IOException
*/ */
public Image read(byte[] src) throws IOException { public Image read(byte[] src) throws IOException {
return ImageWaiter.waitForImage( return ImageIO.read(new ByteArrayInputStream(src));
Toolkit.getDefaultToolkit().createImage(src) }
);
/**
* @param input the data of the image to create
*
* @return the newly created image
* @throws IOException
*/
public Image read(InputStream input) throws IOException {
return ImageIO.read(input);
} }
/** /**

View file

@ -279,7 +279,7 @@ public class ImageWrapper {
/** /**
* Draws another image to this image. * Draws another image to this image.
* *
* @param filename ... * @param image ...
* @param at ... * @param at ...
*/ */
public void drawImage(ImageWrapper image, AffineTransform at) public void drawImage(ImageWrapper image, AffineTransform at)

View file

@ -38,38 +38,6 @@ import helma.image.*;
* A wrapper for an image that uses the ImageIO Framework. * A wrapper for an image that uses the ImageIO Framework.
*/ */
public class ImageIOGenerator extends ImageGenerator { public class ImageIOGenerator extends ImageGenerator {
/**
* @param filename the filename of the image to create
*
* @return the newly created image
* @throws IOException
*/
public Image read(String filename)
throws IOException {
return ImageIO.read(new File(filename));
}
/**
* @param url the URL the filename of the image to create
*
* @return the newly created image
* @throws IOException
*/
public Image read(URL url)
throws IOException {
return ImageIO.read(url);
}
/**
* @param src the data of the image to create
*
* @return the newly created image
* @throws IOException
*/
public Image read(byte[] src)
throws IOException {
return ImageIO.read(new ByteArrayInputStream(src));
}
protected void write(ImageWrapper wrapper, ImageWriter writer, float quality, boolean alpha) throws IOException { protected void write(ImageWrapper wrapper, ImageWriter writer, float quality, boolean alpha) throws IOException {
BufferedImage bi = wrapper.getBufferedImage(); BufferedImage bi = wrapper.getBufferedImage();
@ -111,9 +79,10 @@ public class ImageIOGenerator extends ImageGenerator {
/** /**
* Saves the image. Image format is deduced from filename. * Saves the image. Image format is deduced from filename.
* *
* @param filename ... * @param wrapper the image to write
* @param quality ... * @param filename the file to write to
* @param alpha ... * @param quality image quality
* @param alpha to enable alpha
* @throws IOException * @throws IOException
* @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.lang.String, float, boolean) * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.lang.String, float, boolean)
*/ */
@ -150,10 +119,11 @@ public class ImageIOGenerator extends ImageGenerator {
/** /**
* Saves the image. Image format is deduced from type. * Saves the image. Image format is deduced from type.
* *
* @param out ... * @param wrapper the image to write
* @param type ... * @param out the outputstream to write to
* @param quality ... * @param mimeType the mime type
* @param alpha ... * @param quality image quality
* @param alpha to enable alpha
* @throws IOException * @throws IOException
* @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.io.OutputStream, java.lang.String, float, boolean) * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.io.OutputStream, java.lang.String, float, boolean)
*/ */

View file

@ -93,9 +93,11 @@ public class ImageObject {
} else if (arg instanceof MimePart) { } else if (arg instanceof MimePart) {
img = generator.createImage(((MimePart) arg).getContent()); img = generator.createImage(((MimePart) arg).getContent());
} else if (arg instanceof File) { } else if (arg instanceof File) {
img = generator.createImage(((File) arg).getPath()); img = generator.createImage(((File) arg).getAbsolutePath());
} else if (arg instanceof FileObject) { } else if (arg instanceof FileObject) {
img = generator.createImage(((FileObject) arg).getFile().getPath()); img = generator.createImage(((FileObject) arg).getFile().getAbsolutePath());
} else if (arg instanceof InputStream) {
img = generator.createImage((InputStream) arg);
} else { } else {
Image image = null; Image image = null;
if (arg instanceof BufferedImage) { if (arg instanceof BufferedImage) {