public BufferedImage(int width, int height, int imageType) {
switch (imageType) {
case TYPE_INT_RGB:
cm = new DirectColorModel(24, RED_MASK, GREEN_MASK, BLUE_MASK);
raster = cm.createCompatibleWritableRaster(width, height);
break;
case TYPE_INT_ARGB:
cm = ColorModel.getRGBdefault();
raster = cm.createCompatibleWritableRaster(width, height);
break;
case TYPE_INT_ARGB_PRE:
cm = new DirectColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
32,
RED_MASK,
GREEN_MASK,
BLUE_MASK,
ALPHA_MASK,
true,
DataBuffer.TYPE_INT);
raster = cm.createCompatibleWritableRaster(width, height);
break;
case TYPE_INT_BGR:
cm = new DirectColorModel(24,
RED_BGR_MASK,
GREEN_BGR_MASK,
BLUE_BGR_MASK);
raster = cm.createCompatibleWritableRaster(width, height);
break;
case TYPE_3BYTE_BGR: {
int bits[] = { 8, 8, 8 };
int bandOffsets[] = { 2, 1, 0 };
cm = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
bits,
false,
false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height, width * 3, 3, bandOffsets, null);
}
break;
case TYPE_4BYTE_ABGR: {
int bits[] = { 8, 8, 8, 8 };
int bandOffsets[] = { 3, 2, 1, 0 };
cm = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
bits,
true,
false,
Transparency.TRANSLUCENT,
DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height, width * 4, 4, bandOffsets, null);
}
break;
case TYPE_4BYTE_ABGR_PRE: {
int bits[] = { 8, 8, 8, 8 };
int bandOffsets[] = { 3, 2, 1, 0 };
cm = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
bits,
true,
true,
Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
width, height, width * 4, 4, bandOffsets, null);
}
break;
case TYPE_USHORT_565_RGB:
cm = new DirectColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
16,
RED_565_MASK,
GREEN_565_MASK,
BLUE_565_MASK,
0,
false,
DataBuffer.TYPE_USHORT);
raster = cm.createCompatibleWritableRaster(width, height);
break;
case TYPE_USHORT_555_RGB:
cm = new DirectColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
15,
RED_555_MASK,
GREEN_555_MASK,
BLUE_555_MASK,