在Java中int像素数组

如何在包含像素的int数组中创建新的bmp图像(来自pixelGrabber类的getPixel())?

谢谢

制作一个BufferedImage并调用setPixel。

BufferedImage: http : //download.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferedImage.html

如果你想BMP文件,那么你可以使用ImageIO.write(bufferedImage,“BMP”,新文件(“mybmp.bmp”));

我会给你的ImageIO类的链接,但堆栈溢出阻止我发送垃圾邮件。

在Kotlin:

// As it happens default color model has AARRGGBB format // in other words alpha + RBG val colorModel = ColorModel.getRGBdefault() val raster = colorModel.createCompatibleWritableRaster( horizontalRes, verticalRes) val bufferedImage = BufferedImage( colorModel, raster, colorModel.isAlphaPremultiplied, null) // rawArgbData = array of int's. // every int has format = 0xFF|R|G|B (MSB is alpha) raster.setDataElements( 0, 0, horizontalRes, verticalRes, rawArgbData) // finally save ImageIO.write(bufferedImage, "PNG", File(filePath)) 

在ARGB格式中保存位图可能有问题,请参阅: ImageIO.write bmp不起作用

    Interesting Posts