我想创建一个带有certin宽度,高度(800x600)和位深度为24的 BufferedImage ,我希望图像背景是透明的。
我该怎么做?
感谢你。
答案 0 :(得分:2)
使用构造函数并传递合适的格式参数:
new BufferedImage(w, h, BufferedImage.TYPE_?);
TYPE_在哪里?是定义具有alpha通道格式的常量,如TYPE_INT_ARGB。
编辑:直接来自BufferedImage
/**
* Represents an image with 8-bit RGBA color components packed into
* integer pixels. The image has a <code>DirectColorModel</code>
* with alpha. The color data in this image is considered not to be
* premultiplied with alpha. When this type is used as the
* <code>imageType</code> argument to a <code>BufferedImage</code>
* constructor, the created image is consistent with images
* created in the JDK1.1 and earlier releases.
*/
public static final int TYPE_INT_ARGB = 2;
答案 1 :(得分:1)
这些是BufferedImage的选项:
BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?,?> properties)
BufferedImage(int width, int height, int imageType)
BufferedImage(int width, int height, int imageType, IndexColorModel cm)