如何在java中从包含像素的int数组(来自pixelGrabber类的getPixel())创建新的bmp图像?
由于
答案 0 :(得分:1)
制作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类的链接,但Stack Overflow阻止我发送垃圾邮件。
答案 1 :(得分:-1)
在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格式保存位图可能存在问题,请参阅:jq