Solved

Loading GIF from a byte[] ?

Posted on 1998-01-04
5
360 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
[X]
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
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 136
Java program running SQL query 5 64
Cisco ASA: Java web start no go, asdm launcher no go 3 88
Is there a Google Voice API? 9 71
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

739 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