permaculture playing cards
The moose likes Swing / AWT / SWT and the fly likes How to send image over a network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to send image over a network" Watch "How to send image over a network" New topic

How to send image over a network

Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Since the BufferedImage class does not implement the Serializable interface, how can i send an image over a network, say using RMI.
Since i am a bit (or maybe a byte) weak in graphics, the question may be too simple.
I would be grateful if someone could give me the name of a book to make swing, 2d graphics strong.
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
I think you can go from BufferedImage to a Raster
with getData().
From the Raster you can call getDataBuffer(). The
DataBuffer class is abstract, so you have to find
out (or already know) which subclass you really
have. getDataType() on the DataBuffer can tell you
If your DataBuffer is DataBufferByte, for instance,
then you could get an array byte[][] by calling
getBankData() on the DataBufferByte. Then you have
the data as primitives.
There is an online Programmer's Guide to Java 2D at:
Before the 2D API, the David Geary book "Graphic
Java" was very good. I have not read the later
editions. Look for user reviews at online book sellers.
Dale Mitchell

Joined: Feb 19, 2002
Posts: 3
Depending on what you want to do with the image you could convert the BufferedImage into some other format. In jdk1.2 and 1.3 there is a package called com.sun.image.codec.jpeg that can encode your BufferedImage into a JPEG. This image can be sent via RMI. On the other end, you can use this image as is or use the JPEGImageDecoder class to create a BufferedImage from the transported byte[].

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

This is a client and server I made to transfer any kind of file to anothe computer over a network. It is really rough and REALLY limited and all command line based. But it might give you an idea.

Good luck!

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: How to send image over a network
jQuery in Action, 3rd edition