Methods Summary |
---|
public javax.imageio.metadata.IIOMetadata | convertImageMetadata(javax.imageio.metadata.IIOMetadata arg0, javax.imageio.ImageTypeSpecifier arg1, javax.imageio.ImageWriteParam arg2)
throw new NotImplementedException();
|
public javax.imageio.metadata.IIOMetadata | convertStreamMetadata(javax.imageio.metadata.IIOMetadata arg0, javax.imageio.ImageWriteParam arg1)
throw new NotImplementedException();
|
public static android.graphics.Bitmap | getBitmap()
return bm;
|
public javax.imageio.metadata.IIOMetadata | getDefaultImageMetadata(javax.imageio.ImageTypeSpecifier arg0, javax.imageio.ImageWriteParam arg1)
throw new NotImplementedException();
|
public javax.imageio.metadata.IIOMetadata | getDefaultStreamMetadata(javax.imageio.ImageWriteParam arg0)
throw new NotImplementedException();
|
public javax.imageio.ImageWriteParam | getDefaultWriteParam()
return new PNGImageWriterParam();
|
public void | write(javax.imageio.metadata.IIOMetadata streamMetadata, javax.imageio.IIOImage iioImage, javax.imageio.ImageWriteParam param)
if (output == null) {
throw new IllegalStateException("Output not been set");
}
if (iioImage == null) {
throw new IllegalArgumentException("Image equals null");
}
// AWT???: I think this is not needed anymore
// if (iioImage.hasRaster() && !canWriteRasters()) {
// throw new UnsupportedOperationException("Can't write raster");
//}// ImageOutputStreamImpl
Raster sourceRaster;
RenderedImage img = null;
if (!iioImage.hasRaster()) {
img = iioImage.getRenderedImage();
if (img instanceof BufferedImage) {
sourceRaster = ((BufferedImage) img).getRaster();
} else {
sourceRaster = img.getData();
}
} else {
sourceRaster = iioImage.getRaster();
}
SampleModel model = sourceRaster.getSampleModel();
int srcWidth = sourceRaster.getWidth();
int srcHeight = sourceRaster.getHeight();
int numBands = model.getNumBands();
ColorModel colorModel = img.getColorModel();
int pixelSize = colorModel.getPixelSize();
int bytePixelSize = pixelSize / 8;
int bitDepth = pixelSize / numBands;
// byte per band
int bpb = bitDepth > 8 ? 2 : 1;
boolean isInterlace = true;
if (param instanceof PNGImageWriterParam) {
isInterlace = ((PNGImageWriterParam) param).getInterlace();
}
int colorType = PNG_COLOR_TYPE_GRAY;
int[] palette = null;
if (colorModel instanceof IndexColorModel) {
if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8) {
// Wrong bitDepth-numBands composition
throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
}
if (numBands != 1) {
// Wrong bitDepth-numBands composition
throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
}
IndexColorModel icm = (IndexColorModel) colorModel;
palette = new int[icm.getMapSize()];
icm.getRGBs(palette);
colorType = PNG_COLOR_TYPE_PLTE;
}
else if (numBands == 1) {
if (bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8 && bitDepth != 16) {
// Wrong bitDepth-numBands composition
throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
}
colorType = PNG_COLOR_TYPE_GRAY;
}
else if (numBands == 2) {
if (bitDepth != 8 && bitDepth != 16) {
// Wrong bitDepth-numBands composition
throw new IllegalArgumentException(Messages.getString("imageio.1"));//$NON-NLS-1$
}
colorType = PNG_COLOR_TYPE_GRAY_ALPHA;
}
else if (numBands == 3) {
if (bitDepth != 8 && bitDepth != 16) {
// Wrong bitDepth-numBands composition
throw new IllegalArgumentException(Messages.getString("imageio.1")); //$NON-NLS-1$
}
colorType = PNG_COLOR_TYPE_RGB;
}
else if (numBands == 4) {
if (bitDepth != 8 && bitDepth != 16) {
//Wrong bitDepth-numBands composition
throw new IllegalArgumentException(Messages.getString("imageio.1")); //$NON-NLS-1$
}
colorType = PNG_COLOR_TYPE_RGBA;
}
/* ???AWT: I think this is not needed anymore
int dbufferLenght = bytePixelSize * imageHeight * imageWidth;
DataBufferByte dbuffer = new DataBufferByte(dbufferLenght);
WritableRaster scanRaster = Raster.createInterleavedRaster(dbuffer, imageWidth, imageHeight, bpb * numBands
* imageWidth, bpb * numBands, BAND_OFFSETS[numBands], null);
scanRaster.setRect(((BufferedImage) image).getRaster()// image.getData()
.createChild(0, 0, imageWidth, imageHeight, 0, 0, null));
*/
if (DEBUG) {
System.out.println("**** raster:" + sourceRaster);
System.out.println("**** model:" + model);
System.out.println("**** type:" + colorType);
}
if (model instanceof SinglePixelPackedSampleModel) {
DataBufferInt ibuf = (DataBufferInt)sourceRaster.getDataBuffer();
int[] pixels = ibuf.getData();
// Create a bitmap with the pixel
bm = Bitmap.createBitmap(pixels, srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
// Use Bitmap.compress() to write the image
ImageOutputStream ios = (ImageOutputStream) getOutput();
ImageOutputStreamWrapper iosw = new ImageOutputStreamWrapper(ios);
bm.compress(CompressFormat.PNG, 100, iosw);
} else {
// ???AWT: Add support for other color models
throw new RuntimeException("Color model not supported yet");
}
|