Solved

Loading GIF from a byte[] ?

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 39
firstChar challenge 13 86
Running Jira on Raspberry PI 2? 3 139
Non-recursive backtracking, using a stack 1 53
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now