栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将javafx.scene.image.Image写入文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将javafx.scene.image.Image写入文件?

差不多3年后,我现在有知识去做并回答这个问题。是的,原始答案也是有效的,但它涉及到先将图像转换为BufferedImage,我理想上想完全避免摆动。虽然这确实会输出图像的原始RGBA版本,足以满足我的需要。实际上,由于我正在编写软件来打开结果,所以实际上我只能使用原始BGRA,但是由于gimp无法打开,我认为我会将其转换为RGBA。

Image img = new Image("file:test.png");int width = (int) img.getWidth();int height = (int) img.getHeight();PixelReader reader = img.getPixelReader();byte[] buffer = new byte[width * height * 4];WritablePixelFormat<ByteBuffer> format = PixelFormat.getByteBgraInstance();reader.getPixels(0, 0, width, height, format, buffer, 0, width * 4);try {    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("test.data"));    for(int count = 0; count < buffer.length; count += 4) {        out.write(buffer[count + 2]);        out.write(buffer[count + 1]);        out.write(buffer[count]);        out.write(buffer[count + 3]);    }    out.flush();    out.close();} catch(IOException e) {    e.printStackTrace();}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/463514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号