Solved

Loading GIF from a byte[] ?

Posted on 1998-01-04
5
358 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 85
Java JRE greater than 1.6 5 62
fibonacci ten numbers 4 38
Tomcat: Unable to run tomcat service. 2 19
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

773 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