如何从像素值数组创建图像和已知的宽度和高度..? [英] How to create Image From Array of Pixel Values and known width and height..?

查看:202
本文介绍了如何从像素值数组创建图像和已知的宽度和高度..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1D像素值数组,我可以通过这种方式获得红色,绿色和蓝色。

I have 1D array of pixel values and i can get red, green and blue this way.

int rgb[] = new int[]
        {
            (argb >> 16) & 0xff, //red
            (argb >>  8) & 0xff, //green
            (argb      ) & 0xff  //blue
        };

我知道我要创建的图像宽度高度。
所以,我总共有以下数据。
1)新图像的宽度
2)新图像的高度
3)像素值的一维数组。

I know width height of image as well which I want to create. So, in total I have following data. 1) width of new image 2) height of new image 3) one dimension array of pixel value.

我的主管建议我使用createRaster方法,但函数参数对我来说很难理解。
你能给我一些简单的代码吗?
谢谢。

My supervisor has advised me to use createRaster method but function arguments are hard to understand for me. Can you suggest me some simple code? Thanks.

推荐答案

this 上一篇SO帖子:

public static Image getImageFromArray(int[] pixels, int width, int height) {
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            WritableRaster raster = (WritableRaster) image.getData();
            raster.setPixels(0,0,width,height,pixels);
            return image;
        }

如果你无法理解参数是什么,你应该看看在 Java文档

If you are having trouble understanding what the parameters are, you should take a look at the Java Documentation.

这篇关于如何从像素值数组创建图像和已知的宽度和高度..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆