Solved

Read display a gif using a socket or fileinputstream in applet

Posted on 1997-07-19
3
312 Views
Last Modified: 2006-11-17
I need to read a gif using either a socket connection or FileInputStream, convert to an image and display using graphics.drawImage .  most methods seem to return an array of bytes, which I think I can convert to an image using MemoryImageSource, however I have found no concrete examples and just cannot get it to work.  I would just use getImage but the image is cached at the browser and I can't have that, need fresh reload.  I need a solid example of how to do this.

0
Comment
Question by:dsweeney
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
mann061997 earned 50 total points
Comment Utility
Here's some sample code for a bilevel image:

    byte[] cmR = {(byte)0x00, (byte)0xFF};
    byte[] cmG = cmR;
    byte[] cmB = cmR;
    IndexColorModel cm = new IndexColorModel(1, 2, cmR, cmG, cmB);

    byte[] data;

    ... fill data array, e.g. from file input source.

    Image myImage = createImage(new MemoryImageSource(
                      width,
                      height,
                      cm,
                      data,
                      0,
                      width));
    g.drawImage(myImage, x, y , null);

0
 
LVL 1

Expert Comment

by:mann061997
Comment Utility
I forgot to mention: the byte array must contain a decompressed image, i.e. a pixmap, for the above code to work. If you're working with GIF this means you must first decompress the GIF image.
0
 

Author Comment

by:dsweeney
Comment Utility
The pic will be a JPG, and there is no way for me to decompress  it first (I am using Connectix Quickcam software that simply sends the image it 'sees' to disk every 10 seconds).  I can also save it as a BMP or TIFF file, if this helps??  Also, what the heck is a bilevel image?  I have been trying to get this project online so long that I will give you 200 points and an A if you can provide some code that does the trick!!!  
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

13 Experts available now in Live!

Get 1:1 Help Now