array of bytes to an image

S

steve

I have an array of bytes that I need to save out as an image. I have
tried this

where byte[] type10image is the array of bytes representing the image

Image t10 = null;
t10 = Toolkit.getDefaultToolkit().createImage(type10image);
File output = new File("saved.jpeg");
ImageIO.write(t10, "jpeg", output);

and on the last line on the .write I am getting

cannot find symbol
symbol: method write(java.awt.Image, java.lang.String, java.io.File)
location: class.javax.imageio.ImageIO

and yes I have
import javax.imageio.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

Help? Not sure what is going on.

Thanks
 
S

steve

I have an array of bytes that I need to save out as an image. I have
tried this

where byte[] type10image is the array of bytes representing the image

        Image t10 = null;
        t10 = Toolkit.getDefaultToolkit().createImage(type10image);
        File output = new File("saved.jpeg");
        ImageIO.write(t10, "jpeg", output);

and on the last line on the .write I am getting

cannot find symbol
symbol: method write(java.awt.Image, java.lang.String, java.io.File)
location: class.javax.imageio.ImageIO

and yes I have
import javax.imageio.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

Help? Not sure what is going on.

Thanks

Also tried this

try {
InputStream in = new ByteArrayInputStream(type10image);
BufferedImage bi = javax.imageio.ImageIO.read(in);
File outputfile = new File("saved.jpg");
ImageIO.write(bi, "jpg", outputfile);
}
catch (IOException e){}

and with this I am getting Exception in thread "main"
java.lang.IllegalArgumentException: im == null! occuring on the
ImageIO.write line
 
M

Mark Space

steve said:
I have an array of bytes that I need to save out as an image. I have
tried this

where byte[] type10image is the array of bytes representing the image

Image t10 = null;
t10 = Toolkit.getDefaultToolkit().createImage(type10image);
File output = new File("saved.jpeg");
ImageIO.write(t10, "jpeg", output);

ImageIO.write takes a "RenderImage" for the first argument, not Image.
So it can't find a method called "write" that takes an Image, which is
why you are getting the message.
 
S

steve

steve said:
I have an array of bytes that I need to save out as an image. I have
tried this
where byte[] type10image is the array of bytes representing the image
        Image t10 = null;
        t10 = Toolkit.getDefaultToolkit().createImage(type10image);
        File output = new File("saved.jpeg");
        ImageIO.write(t10, "jpeg", output);

ImageIO.write takes a "RenderImage" for the first argument, not Image.
So it can't find a method called "write" that takes an Image, which is
why you are getting the message.

Problem solved. Got it working!
 
B

blue indigo

Also tried this

try {
InputStream in = new ByteArrayInputStream(type10image);
BufferedImage bi = javax.imageio.ImageIO.read(in);
File outputfile = new File("saved.jpg");
ImageIO.write(bi, "jpg", outputfile);
}
catch (IOException e){}

and with this I am getting Exception in thread "main"
java.lang.IllegalArgumentException: im == null! occuring on the
ImageIO.write line

ImageIO.read() is documented as sometimes returning null. So bi needs to
be checked.

ImageIO.read() may return null if the file cannot be decoded -- it's
broken or it's not in a supported format. Adding plugin classes to the
class path can expand the set of supported formats without the caller of
ImageIO.read() having to add new code though.
 
Joined
Feb 4, 2011
Messages
1
Reaction score
0
steve said:
On Jan 27, 10:23*am, Mark Space <[email protected]> wrote:
> steve wrote:
> > I have an array of bytes that I need to save out as an image. I have
> > tried this

>
> > where byte[] type10image is the array of bytes representing the image

>
> > * * * * Image t10 = null;
> > * * * * t10 = Toolkit.getDefaultToolkit().createImage(type10image);
> > * * * * File output = new File("saved.jpeg");
> > * * * * ImageIO.write(t10, "jpeg", output);

>
> ImageIO.write takes a "RenderImage" for the first argument, not Image.
> So it can't find a method called "write" that takes an Image, which is
> why you are getting the message.


Problem solved. Got it working!



how did you got it working?

here is my code, which has the same error java.lang.IllegalArgumentException: im == null!


String base64String=args[0];(String containing base64 data)


byte[] bytearray = Base64.decode(base64String);
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(bytearray));
ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));


please help me get it work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top