Ok, I will try to answer both, to Anderson and to Lesley.

Anderson: as I understood, you have an image in database and you would
like to show this image in window with the same width and height. First of
all, if you intend to show the image in such window, I assume that wont be
good, because you have to consider also all the borders of the window.
Especially if you are writing an application that would look the same on
all platforms, you have to take into consideration different GUIs. Ok,
enough for this now, I will come to that again later.

What you have to do? Here are the steps:
1. read the image from database
2. create an instance of class java.awt.Image, that contains this image
3.create new window and put this image into (there are several methods,
you can just simply use paint method. Or you can write your own subclass
from class Panel or...)
4. resize window

How you do step 2?
If you have *.gif or *.jpg image, use something like this:
 Image picture = Toolkit.getDefaultToolkit().getImage(path_to_image);

If you have other formats, first check the extension of file and then use
other classes to load image. I wrote some classes for reading BMP, PCX,
TIF and other image formats, but currently I don't know where I stored
them.. Grrrr...

What I meant with step 4?

You can find out dimension of image with two methods of class Image
(getWidth() and getHeight()). It you are gone set that size for window (in
which you would like to show that image), you wont see the actual size of
the image. It will be the difference for windows widht of borders (on all
ways). If you will use method drawImage, like it is written below you will
see all the image, but scalled down for that difference. I solve this so
(I now it is not the best solution, but it works), that I put image
(automaticaly scaled) into window, and than I checked the size of scaled image. Then i 
resized my window so that I added
difference between scaled image and original size of image. And it works.

  public void paint(Graphics g) {
    Dimension D = getSize();
    g. drawImage(picture,0,0,D.width,D.height,this); // this -> I wrote my
                // own Panel that implements interface ImageProducer
  }

If you will have problems with getting image width and height, tell me. I
remember that I wrote a code that went ok with appletviewer, but in
Netscape and Explorer I have to start them again. In that moment I cannot
recal what it was, I can look into the code (because I fixed it) if this
happens to you.

Lesley: finally tha part for you, heh. All the data you need, you said
that is stored in database. I solved almost the same problem with servlet.
I collect all the data from URL, but that's just a minor change for your
needs. Then you will draw your image (you said charts) into virtual memory
image (array int[image_width][image_height] - if you don't know how to
draw in such image, let me know and I'll write you another mail) and than
use some GIFEncoder. I downloaded mine somewhere from internet and change
a little bit (instead of writing a file it uses now output stream). With
this GIFEncoder (you can also write your own) you create a GIF image, but
instead of store it on disk you just simply send it over outputstream
(code bellow)

Steps for you:
- collect all needed data from database
- create image in memory
- create GIF image
- send this image over output stream

small piece of code:
  public void service(HttpServletRequest aRequest, HttpServletResponse
                      aResponse) throws ServletException,
                                        java.io.IOException {
    OutputStream out;
    GifEncoder gif;

    request = aRequest;
    response = aResponse;
    collectParameters();  // collect data from database
    drawImage();  // drav virtual image
    response.setContentType("image/gif");  // set content type on gif
                                            // image
    try {
      out = response.getOutputStream();  // get output stream
      gif = new GifEncoder(new MemoryImageSource // instance of
GIFEncoder(IMAGE_WIDTH,IMAGE_HEIGHT,image,0,IMAGE_WIDTH),out,!false);
      gif.encode();  // create gif image
      out.flush();  // send this image over net
    } catch (Exception e) { // nothing hapens in case of any exception
    }
  }

How you than use that?

I don't know exactly what you need, but I guess
that you will wrote servlet that somehow (maybe via URL?) get which data
it will use for gif image and than you will show that image on your HTML
page. You can use just simpy something like this:

<IMG SRC="http://server/nameOfServlet?whichdata">

and because servlet returns gif image (that is set with method
setContentType) that's all. You will get the picture you need (and you
drawed, of course).

Anderson and Lesley, did I answered yours questions? If not, tell me.

I have also a question, related to this mailing list. Always when I want
to send a question or just a reply to someones problems, I always got
several anoying mails, that my mail couldn't be delivered. Am I the only
one that gets this crap? Because everytime I hate that more. And this will
happen also now, when i send this mail. Grrrr...

bye,
Branko

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to