ObjectWeb Consortium
Search ObjectWeb Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | enhydra List | September 2000 Index

<--  Date Index  --> <--  Thread Index  -->

AW: Enhydra: Dynamic graphics in your page


Hi!

did some dynamic image creation a while back using plain servlets.
Maybe the follwoing snippet helps:

(Note: this is just a snippet, not sure if it will run exactly like this, but 
it should get the idea across, and give some pointers
which api calls to look at.
It displays the value of the get-paramter named text in a box.)

HTH

-markus

P.S. Let me know if you succeed.
------------------------------------------------------------------

import java.awt.image.*;
import java.awt.*;
import com.sun.image.codec.jpeg.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class GraphServlet extends HttpServlet {
//Initialize global variables

  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
  }
//Process the HTTP Get request

  public void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
    response.setContentType("image/jpeg");
    int w = 300;
    int h = 100;
    int pix[] = new int[w * h];
    BufferedImage mImage =  new BufferedImage(w, h, 
BufferedImage.TYPE_INT_RGB);
    Graphics2D mGraphics = mImage.createGraphics();
    mGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
RenderingHints.VALUE_ANTIALIAS_ON);
    mGraphics.setRenderingHint(RenderingHints.KEY_RENDERING, 
RenderingHints.VALUE_RENDER_QUALITY);
    mGraphics.setColor(Color.white);
    mGraphics.fillRect(0, 0, w, h);
    mGraphics.setColor(Color.black);
    mGraphics.setFont(new Font("Frutiger Italic", Font.PLAIN, 36));
    
mGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
0.5f));
    mGraphics.drawString(request.getParameter("text"), 0, h - 10);
    JPEGImageEncoder encoder =
      JPEGCodec.createJPEGEncoder(response.getOutputStream());
    JPEGEncodeParam param =
      encoder.getDefaultJPEGEncodeParam(mImage);
    param.setQuality(0.75f,true);
    encoder.encode(mImage,param);
    // mEnc.encode();
    st.disconnect();
  }
//Get Servlet information

  public String getServletInfo() {
    return "graph.GraphServlet Information";
  }
}

-------------------------------------

> -----Ursprüngliche Nachricht-----
> Von: owner-enhydra@xxxxxxxxxxx [mailto:owner-enhydra@xxxxxxxxxxx]Im
> Auftrag von Laurent Roméo
> Gesendet: Montag, 25. September 2000 17:23
> An: enhydra@xxxxxxxxxxx
> Betreff: Re: Enhydra: Dynamic graphics in your page
>
>
> Le lun, 25 sep 2000, vous avez écrit :
> > Laurent,
> >     I am doing something similar in my application.  It involves 
> > displaying a
> > large stack of images in a jpeg format.  (30 -40 images @ 40 KB each)
> >
> > This is done in a few steps.
> >
> > 1.  Create a temporary folder that is accessible via apache based on the 
> > name of
> > the session (24 characters of giberish )
>
> NO !!!
>
> It is exactly what I want to avoid....
>
> I'm currently working, I'll tell you if I succeed.
>
> > 2.  Convert the images from raw data to jpegs named img0, img1, img2 ...
> > 3.  Have a PO that calls an applet to view these images.  (I use an applet
> > because it is necessary to be able to adjust contrast on my images... to 
> > locate
> > the images, i just change a parameter in the PO that calls the applet.)
> > 4.  The applet then downloads the 40 or so jpegs via http from
> > myserver.com/output/<sessionname>/imgN.jpg into a vector.
> > 5.  Then the applet is used to flip through the images
> > 6.  I haven't done this part yet, but: On stop() or destroy() the applet 
> > calls
> > its loader with the event being "done", at which point the po calls some 
> > code to
> > remove that temporary file with the 40 jpegs in it.
> >
> >     The biggest problem with the design (i think) is the temporary 
> > folder.  If
> > the applet fails to send over that it is done, i end up with a bunch of 
> > files
> > cluttering up my server.  This means possibly using some sort of timer to 
> > delete
> > them.
> >
> > I am also interested in hearing any ideas on how else one might create and
> > display dynamic images in Enhydra.
> >
> > Regards,
> > Ben
> >
> >
> >
> > "Laurent Roméo" wrote:
> >
> > > Hi,
> > >
> > > I would like to do one thing, but before diving inside all the APIs, I 
> > > would
> > > like to test if anybody has already experienced it...
> > >
> > > My problem is to generate a dynamic graphic from a template one. That 
> > > could be
> > > the case if you want to display chart or every kind of statistics.
> > >
> > > I want to integrate it in my page using a tag like :
> > >
> > > <img src="http://www.mydomain.com/app/Dynamicgraphics.po>
> > >
> > > Doing so, it could be possible to integrate this graphics inside my 
> > > page where
> > > I put every kind of comments.
> > >
> > > My idea is to use an API like Java2D ( maybe another one is better), 
> > > and to
> > > return a MIME TPYE appropriated.
> > >
> > > Any examples ?
> > >
> > > --
> > >
> > >   Cordialement,
> > >
> > > Laurent ROMEO
> > > -------------
> > >
> > > Directeur R&D
> > > AGISphere S.A.
> > >
> > > http://www.agisphere.com/
> > >
> > > laurent.romeo@xxxxxxxxxxxxx
> > >
> > > 01.47.45.99.92
> > > 06.88.08.49.50
> > >
> > > -----------------------------------------------------------------------------
> > > To unsubscribe from this mailing list, send email to 
> > > majordomo@xxxxxxxxxxx
> > > with the text "unsubscribe enhydra" in the body of the email.
> > > If you have other questions regarding this mailing list, send email to
> > > the list admin at owner-enhydra@xxxxxxxxxxxx
> >
> > -----------------------------------------------------------------------------
> > To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
> > with the text "unsubscribe enhydra" in the body of the email.
> > If you have other questions regarding this mailing list, send email to
> > the list admin at owner-enhydra@xxxxxxxxxxxx
> --
>
>   Cordialement,
>
> Laurent ROMEO
> -------------
>
> Directeur R&D
> AGISphere S.A.
>
> http://www.agisphere.com/
>
> laurent.romeo@xxxxxxxxxxxxx
>
> 01.47.45.99.92
> 06.88.08.49.50
>
> -----------------------------------------------------------------------------
> To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
> with the text "unsubscribe enhydra" in the body of the email.
> If you have other questions regarding this mailing list, send email to
> the list admin at owner-enhydra@xxxxxxxxxxxx
>

-----------------------------------------------------------------------------
To unsubscribe from this mailing list, send email to majordomo@xxxxxxxxxxx
with the text "unsubscribe enhydra" in the body of the email.
If you have other questions regarding this mailing list, send email to
the list admin at owner-enhydra@xxxxxxxxxxxx




<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.