cyberco schrieb:
> I want to get the bytes from a BufferedImage to send it over the line,
> how can I achieve that? I seems to be trickier than I thought.
See ImageIO
>I want to get the bytes from a BufferedImage to send it over the line,
>how can I achieve that? I seems to be trickier than I thought.
you can't serialise it. The actual form is platform dependent, so it
might not mean anything when you got to the other end. What you want
to do is extract an array of ints or shorts or bytes and send that by
serialisation or DataOutputStream.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 12 Feb 2006 16:47 GMT
On Sun, 12 Feb 2006 16:36:20 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :
>>I want to get the bytes from a BufferedImage to send it over the line,
>>how can I achieve that? I seems to be trickier than I thought.
[quoted text clipped - 3 lines]
>to do is extract an array of ints or shorts or bytes and send that by
>serialisation or DataOutputStream.
you can convert it to png or jpg format and send that.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
cyberco - 12 Feb 2006 18:46 GMT
Yes, getting the bytes is what I'm trying to do. Unfortunately ImageIO
does not have any convenience methods for that purpose. Any other
suggestions?
Timo Stamm - 12 Feb 2006 19:04 GMT
cyberco schrieb:
> Yes, getting the bytes is what I'm trying to do.
Roedy pointed out why BufferedImage itself isn't serializable.
You could access the matrices and send that data over the line, but you
will most likely need some meta data for different color models etc. and
will reinvent the wheel, because there are already dozens of image file
formats available through ImageIO.
> Unfortunately ImageIO does not have any convenience methods for that
> purpose.
What could be more convenient than:
ImageIO.write(RenderedImage im, String formatName, OutputStream output);
?
Timo
cyberco - 12 Feb 2006 22:29 GMT
Oops! Sorry, Timo, you're right. My bad. I overlook ImageIO.write(). I
succeeded getting the byte[] in the following way.
####################
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufImage, formatName, baos);
byte[] bytesOut = baos.toByteArray();
Roedy Green - 13 Feb 2006 09:26 GMT
>Yes, getting the bytes is what I'm trying to do. Unfortunately ImageIO
>does not have any convenience methods for that purpose. Any other
>suggestions?
It can write to an OutputStream. Make that a ByteArrayOutputStream.
see
http://mindprod.com/jgloss/imageio.html#TOBYTES
for how.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
cyberco - 13 Feb 2006 21:33 GMT
Excellent examples, Roedy! Thanks for the link!
opalpa@gmail.com opalinski from opalpaweb - 13 Feb 2006 22:48 GMT
You can serialize ImageIcon after making an ImageIcon from
BufferedImage.
Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
cyberco schrieb:
> I want to get the bytes from a BufferedImage to send it over the line,
> how can I achieve that? I seems to be trickier than I thought.
If you know the type of the data buffer of the BufferedImage its easy:
int[] t =
((DataBufferInt)(myBufferedImage).getRaster().getDataBuffer()).getData();
with DataBufferByte it works the same.