从像素值创建图像

编程入门 行业动态 更新时间:2024-10-27 14:18:56
本文介绍了从像素值创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在java中...我有一个RGB像素的整数数组,意味着我的程序的输出如下:'

In java...I have an integer array of RGB pixels, means output of my program is as follows: '

Pixel 1: 255 200 191 231 Pixel 2: 255 237 028 036 Pixel 3: 255 034 177 076 Pixel 4: 255 085 140 066 Pixel 5: 255 200 191 231 Pixel 6: 255 237 028 036 Pixel 7: 255 231 188 167 Pixel 8: 255 237 028 036 Pixel 9: 255 237 028 036 Pixel 10: 255 063 072 204 Pixel 11: 255 226 125 144 Pixel 12: 255 063 072 204 Pixel 13: 255 200 191 231 Pixel 14: 255 062 187 099 Pixel 15: 255 255 127 039 Pixel 16: 255 255 127 039 Pixel 17: 255 200 191 231 Pixel 18: 255 212 177 189 Pixel 19: 255 063 072 204 Pixel 20: 255 040 158 100 Pixel 21: 255 034 177 076 Pixel 22: 255 237 028 036 Pixel 23: 255 248 253 249 Pixel 24: 255 165 169 231 Pixel 25: 255 200 191 231

如何使用上述数据创建尺寸为5 x 5的图像.. 。?'

How can I create image of size 5 x 5 image using the above data...?'

推荐答案

创建 BufferedImage 获取来自BufferedImage 的 Graphics / Graphics2D 对象,并使用 Graphics 对象绘制像素。

Creating a BufferedImage getting the Graphics/Graphics2D object from the BufferedImage and painting with the Graphics object the pixels.

BufferedImage可以存储为带有 ImageIO 的文件,或显示在自己的 Component / JComponent

The BufferedImage can be stored as a File with ImageIO or displayed in an Own Component/JComponent

一位伪代码

BufferedImage bi = new BufferedImage(5,5,BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) bi.getGraphics(); while(i < 25){ g.setColor(new Color(See Api for more details on how to create a Color); g.drawRect(i/5, i%5, 1,1); }

现在你要保存一个BufferdImage ImageIO

Now you have a BufferdImage to be saved with ImageIO

ImageIO.write(bi, "png", new File(output));

或者获取一个新的JComponent并覆盖它的paint方法。这个任务有足够的资源。

Or get a New JComponent and overwrite its paint Method. There are plenty resources for this task.

更多推荐

从像素值创建图像

本文发布于:2023-06-08 14:28:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/583077.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:像素   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!