wood burning stoves 2.0*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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
Author

How to send image over a network

Garry Kalra
Ranch Hand

Joined: May 25, 2001
Posts: 111
Hi,
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.
Garry
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
Garry,
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
that.
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:
http://java.sun.com/products/jdk/1.2/docs/guide/2d/spec/j2d-title.fm.html
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.
HTH,
Joe
Dale Mitchell
Greenhorn

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[].


Dale
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
Client.java

Server.java

Good luck!


GenRocket - Experts at Building Test Data
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to send image over a network