tags:

views:

213

answers:

4

I am creating an application in java which will be the part of an external application. My application contains a viewport which shows some polygons and stuff like that. The external application needs to get the image of the viewport in gif format. For that it calls a method in an interface (implemented by my application) and my application returns the image. The external application needs to store the image in database (or something related to it which I dont need to worry about).

My question is:- What should be the data container type of the image when my application send it to the external application? I mean what should be the return type of the method? Currently my gif encoder class returns a byte array. Is there any other 'better' option?

+3  A: 

A byte array could be appropriate if you expect the GIFs to be small, but you might consider using an OutputStream so you can stream bits more efficiently.

Even if today you just return a fully-populated ByteArrayOutputStream, this would allow you to change your implementation in future without affecting cilent code.

Jason Cohen
the gif image will be of size 150 X 150 pixels.
Shree
That's nice and small. A byte array is fine.
Jason Cohen
+2  A: 

A more intuitive return type might be java.awt.Image.

Here are some examples: http://www.google.com/codesearch?q=java+gif+image&hl=en&btnG=Search+Code

Neal Swearer
but the java.awt.Image object will be platform and format independent. The external application requires a gif image.
Shree
A: 

If your 'application' is actually calling a Java method then it should understand Java return types and you should return java.awt.image.

If you are doing this through some kind of remote procedure that can't understand Java types I would return a byte array and let the receiving app decode it.

DJClayworth
A: 

I'd create two methods:

  1. First method creates the image and returns a java.awt.Image. Here you can put the drawing part of your method.
  2. The second method creates a gif representation of the java.awt.Image as requested by the external application. It should return OutputStream as already suggested.
asalamon74