private void writeBKGD() throws IOException
	{
		if (param.isBackgroundSet())
		{
			ChunkStream cs = new ChunkStream("bKGD");

			switch (colorType)
			{
				case PNG_COLOR_GRAY:
				case PNG_COLOR_GRAY_ALPHA:
					int gray = ((mxPngEncodeParam.Gray) param)
							.getBackgroundGray();
					cs.writeShort(gray);
					break;

				case PNG_COLOR_PALETTE:
					int index = ((mxPngEncodeParam.Palette) param)
							.getBackgroundPaletteIndex();
					cs.writeByte(index);
					break;

				case PNG_COLOR_RGB:
				case PNG_COLOR_RGB_ALPHA:
					int[] rgb = ((mxPngEncodeParam.RGB) param)
							.getBackgroundRGB();
					cs.writeShort(rgb[0]);
					cs.writeShort(rgb[1]);
					cs.writeShort(rgb[2]);
					break;
			}

			cs.writeToStream(dataOutput);
			cs.close();
		}
	}