Home pageFind It!Contact PJAPJA documentation

PJA

 PJA Toolkit forum

This forum is dedicated to PJA Toolkit.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject Java 2D

arulanandam

Member since : Jul 29, 2003
Messages : 1
 Jul 29, 2003 at 10:37 AM
I was able to develop and test a servlet that generates gifs. It uses new PJAImage() method along with pjaf font files.
There was no anti-aliasing done, therefore no smoother edges. I guess i need to use Java 2D methods. Will this run on a server with no X11 libraries
I would appreciate if anyone would post the sample code for this functionality using PJA.

thanks,
arul

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Aug 1, 2003 at 9:45 AM
The PJAGraphics object return by the getGraphics() method of the PJAImage class don't have antialiasing capabilities.
If you want to draw using antialiasing you'll have to use the BufferredImage class on a machine with the basic X11 libs installed (see http://www.eteks.com/pja/en/forum/viewSubject.jsp?subjectId=38 for a list of these libs). For example :
------
<%@ page contentType="image/jpeg"
import="java.awt.image.*,java.awt.*,com.sun.image.codec.jpeg.*" %>
<% // Create an offscreen image 100 x 100 pixels
BufferedImage image = new BufferedImage (100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)image.getGraphics();
// Change Rendering hints to use antialias
g.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// Draw into the image a black circle with the text Hello on a yellow background
g.setColor (Color.yellow);
g.fillRect (0, 0, 100, 100);
g.setColor (Color.black);
g.drawOval (0, 0, 99, 99);
g.drawString ("Hello", 30, 50);
// Create a JPEG encoder to send the image at JPEG format
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(response.getOutputStream());
encoder.encode(image);
response.getOutputStream().close (); %>
------
Copy this code in a JSP file named for example testAntialiasing.jsp, put it on your web server and test it.

If you use the JDK 1.4, the easiest way to make this program work in a headless environment is to set the java.awt.headless to true, for example using the java command following option :
------
-Djava.awt.headless=true
------

If you use the JDK 1.3 or 1.2 you may use PJA Toolkit to make it work. All you have to do is specifying the java command following options (with correct paths) :
------
-Xbootclasspath/a:/path/to/pja.jar
-Dawt.toolkit=com.eteks.awt.PJAToolkit
-Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment
-Djava.awt.fonts=/path/to/jdk/jre/lib/fonts
------

If you use Tomcat 4.1, these options may be set in the environment variable JAVA_OPTS. For other web servers have a look at the other messages on this forum or try a search on google.
---
Manu (moderator/modérateur)


Home pageFind It!ContactTop

© Copyrights 1997-2023 eTeks - All rights reserved

PJAPJA documentation