Solved

Image not serializable

Posted on 1998-11-13
5
272 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

860 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