2

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. 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?

1
  • 6
    I suggest that you use {} on all for loops. It will minimize the risk of bugs. Commented Sep 25, 2012 at 14:01

1 Answer 1

1

You are passing the wrong arguments to ImageIO.write(). From the docs, here are the 3 possibilities:

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:

ImageIO.write(img, "jpg", new File("abc.jpg");
Sign up to request clarification or add additional context in comments.

2 Comments

On a side note, I agree with Maba, throw {} on every loop =)
Seconded :) . I can't even write loops without {} anymore :D .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.