java中int像素数组转bmp

发布于 2024-09-18 15:39:29 字数 85 浏览 2 评论 0原文

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

谢谢

How do i create new bmp image in java from int array that contains pixels (from getPixel() of pixelGrabber class) ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春如此纠结 2024-09-25 15:39:29

制作 BufferedImage 并调用 setPixel。

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

如果你想要 BMP 文件,那么你可以使用 ImageIO.write(bufferedImage,"BMP", new File(" mybmp.bmp"));

我会给你 ImageIO 类的链接,但 Stack Overflow 阻止我发送垃圾邮件。

Make a BufferedImage and call setPixel.

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

If you want BMP file then you can use ImageIO.write(bufferedImage,"BMP", new File("mybmp.bmp"));

I would give you the link to ImageIO class but Stack Overflow is preventing me from spamming.

御守 2024-09-25 15:39:29

在 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。写bmp不行

In 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))

There may be a problem with saving bitmap in ARGB format, see this: ImageIO.write bmp does not work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文