* 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 javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
@ -136,6 +136,18 @@ public abstract class ImageGenerator {
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 filter ...
@ -172,9 +184,7 @@ public abstract class ImageGenerator {
* @throws IOException
*/
public Image read(String filename) throws IOException {
return ImageWaiter.waitForImage(
Toolkit.getDefaultToolkit().createImage(filename)
);
return ImageIO.read(new File(filename));
}
/**
@ -184,9 +194,7 @@ public abstract class ImageGenerator {
* @throws IOException
*/
public Image read(URL url) throws IOException {
return ImageWaiter.waitForImage(
Toolkit.getDefaultToolkit().createImage(url)
);
return ImageIO.read(url);
}
/**
@ -196,9 +204,17 @@ public abstract class ImageGenerator {
* @throws IOException
*/
public Image read(byte[] src) throws IOException {
return ImageWaiter.waitForImage(
Toolkit.getDefaultToolkit().createImage(src)
);
return ImageIO.read(new ByteArrayInputStream(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.
*
* @param filename ...
* @param image ...
* @param 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.
*/
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 {
BufferedImage bi = wrapper.getBufferedImage();
@ -111,9 +79,10 @@ public class ImageIOGenerator extends ImageGenerator {
/**
* Saves the image. Image format is deduced from filename.
*
* @param filename ...
* @param quality ...
* @param alpha ...
* @param wrapper the image to write
* @param filename the file to write to
* @param quality image quality
* @param alpha to enable alpha
* @throws IOException
* @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.
*
* @param out ...
* @param type ...
* @param quality ...
* @param alpha ...
* @param wrapper the image to write
* @param out the outputstream to write to
* @param mimeType the mime type
* @param quality image quality
* @param alpha to enable alpha
* @throws IOException
* @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) {
img = generator.createImage(((MimePart) arg).getContent());
} else if (arg instanceof File) {
img = generator.createImage(((File) arg).getPath());
img = generator.createImage(((File) arg).getAbsolutePath());
} 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 {
Image image = null;
if (arg instanceof BufferedImage) {