简体   繁体   English

在Java中从像素数组创建图像

[英]Create image from pixel array in java

Here is my snippet. 这是我的片段。 My original array is a[3][][] and the rgb values are stored in there I want to create a new image from them. 我的原始数组是a[3][][] ,rgb值存储在其中,我想根据它们创建一个新图像。 The last line of the following code results in symbol not found. 以下代码的最后一行导致找不到符号。

BufferedImage img=newBufferedImage(bi.getWidth(),bi.getHeight(),BufferedImage.TYPE_INT_RGB);
for(int r=0; r<bi.getHeight(); r++)
    for(int c=0; c<bi.getWidth(); c++)
    {
        int red=a[0][r][c];
        int green=a[1][r][c];
        int blue=a[2][r][c];
        int rgb = (red << 16) | (green << 8) | blue;
        img.setRGB(c, r, rgb);
    }
ImageIO.write(img,"jpg", "abc.jpg");

Any suggestions? 有什么建议么?

You are passing the wrong arguments to ImageIO.write() . 您将错误的参数传递给ImageIO.write() From the docs , here are the 3 possibilities: 在docs中 ,这是3种可能性:

write(RenderedImage im, String formatName, File output) 
write(RenderedImage im, String formatName, ImageOutputStream output) 
write(RenderedImage im, String formatName, OutputStream output)

If you want to write the image to a file called abc.jpg , maybe try: 如果要将图像写入名为abc.jpg的文件,请尝试:

ImageIO.write(img, "jpg", new File("abc.jpg");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM