Solved

Read display a gif using a socket or fileinputstream in applet

Posted on 1997-07-19
3
315 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
ID: 1223419
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
ID: 1223420
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
ID: 1223421
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

867 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

16 Experts available now in Live!

Get 1:1 Help Now