Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Loading GIF from a byte[] ?

Posted on 1998-01-04
5
359 Views
Last Modified: 2008-03-10
How can my Applet convert a byte array in "gif89" format
to an Image object?
as you know, there is no "getImage(byte b[])".. only
"getImage(URL u)" or "getImage(File f)"
Since it's an Applet, writing it as a file and loading it with getImage(file) won't work, and neither will trying to set up a "server" on the local machine that will return it to me as a url... (Applet security... arghhh....)

I know there are some classes to do that in sun.awt.image,
but those won't usually be available for me in normal java enabled browsers!
any known workaround for this problem??
even one that only works on MSIE and Netscape....

(I saw that many people are fighting this question in several newsgroups, it's a good example of BAD awt design!)
Thanks,
Ofer Tal
Israel.
0
Comment
Question by:ofer052997
5 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1231924
I think you are right in that you cannot convert what you have into a form where GetImage can deal with it.  Again, JAVA is saving us from ourselves and our impure motives ;-)

How did you get the GIF image into the byte[] to start with?  I assume that you have built it in your applet.  If so, rather than build a GIF in memory (or along with doing that if you must) just draw the image in the applet.
0
 
LVL 4

Expert Comment

by:russgold
ID: 1231925
Actually, you can do this. It's not obvious, but the AWT does support it; however, jhance has already given you an answer. If you like it - fine; otherwise, reject it and let someone else try.
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1231926
Actualy there a several ways it can be done. Though as russgold states, none of them are obvious.
0
 

Author Comment

by:ofer052997
ID: 1231927
first of all... loading an image as a byte[] is not a problem..
just get the InputStream of the URL/URLConnection, and start read()'ing!
of course, if I would have built the image myself in memory, I would simply use the MemoryImageSource to display it.

in JDK1.1 there is a simple solution - the new Toolkit has a method createImage(byte b[]) that decodes the Image from gif/jpg format directly from the byteStream (BTW - the "impure" motivation for my question was an attempt to "stream" Images through a socket OR read many small gifs in one connection...).
Just to be clear - my question is weather the same thing can be done in a way that all (major) Java enabled browsers can display the Image. (Even those who don't support JDK1.1.x) - Netscape4/MSIE4 do it perfectly with the new method call!.

Ofer Tal
0
 
LVL 4

Accepted Solution

by:
russgold earned 400 total points
ID: 1231928
Here is how I would do it in JDK 1.02:

Implement the ImageProducer interface with a class which knows how to convert GIF format into pixels stored in another byte array (this means that you have to write your own GIF interpreter).  Then, simply deliver those pixels as a byte array to the connected ImageConsumer when startProduction is called.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
fibonacci ten numbers 4 45
even odd program using while loop 3 60
Fast way to search item into Java Array (Rhino compatible) 2 31
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

856 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