public class WebdbImage
{
- // imageTypes
- public final static int WEBDB_JPG=0;
- public final static int WEBDB_GIF=1;
-
// default values for scaling
private int maxIconSize=120;
private int maxImageSize=640;
private byte[] iconData;
private byte[] imageData;
- private int imageType;
private int iconWidth;
private int iconHeight;
// constructor
- public WebdbImage(byte[] image, int type)
+ public WebdbImage(byte[] image)
throws IOException
{
- imageType=type;
planarImage = JAI.create("stream",new ByteArraySeekableStream(image));
scaleImage();
}
- public WebdbImage(byte[] image, int type, int iconMax)
+ public WebdbImage(byte[] image, int iconMax)
throws IOException
{
- imageType=type;
maxIconSize=iconMax;
planarImage = JAI.create("stream",new ByteArraySeekableStream(image));
scaleImage();
}
- public WebdbImage(byte[] image, int type, int iconMax, int imageMax)
+ public WebdbImage(byte[] image, int iconMax, int imageMax)
throws IOException
{
- imageType=type;
maxIconSize=iconMax;
maxImageSize=imageMax;
planarImage = JAI.create("stream",new ByteArraySeekableStream(image));
public byte[] getImage() {
if (imageData==null) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-
- switch (imageType) {
- case WEBDB_JPG:
- JAI.create("encode", planarImage, outStream, "JPEG", null);break;
- case WEBDB_GIF:
- JAI.create("encode", planarImage, outStream, "JPEG", null);break;
- default:
- System.err.println("unknown image format: " + imageType);
- }
-
+ // @todo the choice of PNG or JPEG should be made configurable
+ JAI.create("encode", planarImage, outStream, "PNG", null);
imageData = outStream.toByteArray();
}
return imageData;
InterpolationBilinear interp = new InterpolationBilinear();
PlanarImage temp = JAI.create("scale", planarImage, scale, scale, 0.0F, 0.0F, interp);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- /** @todo gif */
- switch (imageType) {
- case WEBDB_JPG:
- JAI.create("encode", temp, outStream, "JPEG", null);break;
- case WEBDB_GIF:
- JAI.create("encode", temp, outStream, "JPEG", null);break;
- default:
- System.err.println("unknown image format: " + imageType);
- }
+ // @todo the choice of PNG or JPEG should be made configurable
+ JAI.create("encode", temp, outStream, "PNG", null);
iconData = outStream.toByteArray();
iconWidth=temp.getWidth();
iconHeight=temp.getHeight();