private void writeEmbedded(IIOImage image,
ImageWriteParam bmpParam) throws IOException {
String format =
compressionType == BMPConstants.BI_JPEG ? "jpeg" : "png";
Iterator iterator = ImageIO.getImageWritersByFormatName(format);
ImageWriter writer = null;
if (iterator.hasNext())
writer = (ImageWriter)iterator.next();
if (writer != null) {
if (embedded_stream == null) {
throw new RuntimeException("No stream for writing embedded image!");
}
writer.addIIOWriteProgressListener(new IIOWriteProgressAdapter() {
public void imageProgress(ImageWriter source, float percentageDone) {
processImageProgress(percentageDone);
}
});
writer.addIIOWriteWarningListener(new IIOWriteWarningListener() {
public void warningOccurred(ImageWriter source, int imageIndex, String warning) {
processWarningOccurred(imageIndex, warning);
}
});
writer.setOutput(ImageIO.createImageOutputStream(embedded_stream));
ImageWriteParam param = writer.getDefaultWriteParam();
//param.setDestinationBands(bmpParam.getDestinationBands());
param.setDestinationOffset(bmpParam.getDestinationOffset());
param.setSourceBands(bmpParam.getSourceBands());
param.setSourceRegion(bmpParam.getSourceRegion());
param.setSourceSubsampling(bmpParam.getSourceXSubsampling(),
bmpParam.getSourceYSubsampling(),
bmpParam.getSubsamplingXOffset(),
bmpParam.getSubsamplingYOffset());
writer.write(null, image, param);
} else
throw new RuntimeException(I18N.getString("BMPImageWrite5") + " " + format);
}