Solved

Image not serializable

Posted on 1998-11-13
5
264 Views
Last Modified: 2012-06-22
May I know how can I grap the image in a canvas a send it to a client and based on the object received, the client will paint the image back to a canvas...

I've tried the writeObject function but it is not able to write an Image object coz Image object does not implements java.io.Serializable
0
Comment
Question by:ctusa
  • 3
5 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 100 total points
ID: 1227407
You can use the PixelGrabber class from the java.awt.image package to get an integer array that represents the image. Use the constructor that takes an Image argument:

public PixelGrabber(Image img,int x,int y,int w,int h,int []pix,int off,int scansize);

The production of pixel data is initiated with the command:

public boolean grabPixels() throws InterruptedException;

from the same class.
You can break this down into bytes, send it across, and on the other end it can be reassembled with a Toolkit.createImage call.

0
 
LVL 16

Expert Comment

by:imladris
ID: 1227408
P.S. there is a createImage method in the Toolkit that takes a byte array as an argument.

0
 
LVL 16

Expert Comment

by:imladris
ID: 1227409
P.P.S. scansize can simply be set to the width of the image in pixels.

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1227410
you have to trap the Image pixel data into a byte array, then (eventually) encode it, than send it
, decode it and show it

so very quickly
Image image = new Image (....mycanvas.getSize())  - creaty new image with the size of canvas
mycanvas.paint(image.getGraphics())  - trap the canvas image into an offscreen image

PixelGrabber pg = new PixelGrabber(imgage, x, y, w, h, pixels, 0, w); - to grab pixels from the image
(see java.awt.image.PixelGrabber  docs)
than you can
1. code the byte array as a Gif file and use Toolkit.CreateImage(bytes) on the client computer
2. send the raw data and implement ImageProducer that creates Image from the raw data

I have no time to write you sample code at moment, so if you have more specific questions please post them here, i'll try to answer (an post code) during the weekend ...
Also can give you the URL of free GIF encoder (byte[] -> gifData) with sources if you need it

hope this helps
  heyhey

0
 

Author Comment

by:ctusa
ID: 1227411
Thanx, but I noticed that the conversion of int[] to byte[] is very very slow... is there a faster way...? That's b4 sending across the network...juz local processing power only...
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question