WrongParameterException
{
PixelImage image = getImage();
if (image == null)
{
throw new MissingParameterException("No image available for saving.");
}
width = image.getWidth();
height = image.getHeight();
setBoundsIfNecessary(width, height);
width = getBoundsWidth();
height = getBoundsHeight();
if (image instanceof Paletted8Image)
{
Palette palette = ((Paletted8Image)image).getPalette();
int numEntries = palette.getNumEntries();
if (numEntries < 1 || numEntries > 256)
{
throw new WrongParameterException("Palette of image to be saved must have 1..256 entries.");
}
bitsPerPixel = 8;
// determine minimum number of bits per pixel necessary to store image
for (int i = 1; i <= 8; i++)
{
if ((1 << i) >= numEntries)
{
bitsPerPixel = i;
break;
}
}
}
else
if (image instanceof Gray8Image)
{
bitsPerPixel = 8;
}
else
if (image instanceof BilevelImage)
{
bitsPerPixel = 1;
}
else
{
throw new UnsupportedTypeException("Unsupported image type: " + image.getClass().getName());
}
out = getOutputAsDataOutput();
if (out == null)
{
throw new MissingParameterException("Output stream / random access file parameter missing.");
}
// now write the output stream
try
{
writeStream();