在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.
更多推荐
从像素值创建图像
发布评论