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 Creating a thumbnail image using PJA

Catriona

Member since : Aug 6, 2003
Messages : 1
 Aug 6, 2003 at 3:23 PM
Hello,

I want to create a thumbnail from an image. I am developing on Windows, but this will be running on a headless server (if it ever works). I have the following function. It compiles, but I can't get it to run. Please can you help me?

private static PJAToolkit m_pjaToolkit;

static
{
m_pjaToolkit = new PJAToolkit();
}

public static void createThumbnail(String orig, String thumb, int maxDim, PrintWriter out) {
try {


System.setProperty ("awt.toolkit", "com.eteks.awt.PJAToolkit");

// Get the image from a file.
//Image inImage = new ImageIcon(orig).getImage(); // original
/* IT GETS HERE< THEN GOES STRAIGHT TO THE EXCEPTION */
PJAImage inImage = (PJAImage)new ImageIcon(m_pjaToolkit.getImage(orig)).getImage();(new FileInputStream (orig), true));

// Determine the scale.
double scale = (double)maxDim/(double)inImage.getHeight(null);
if (inImage.getWidth(null) > inImage.getHeight(null))
{
scale = (double)maxDim/(double)inImage.getWidth(null);
out.println("<p>getting scale of image</p>");
}

// Determine size of new image. One of them
// should equal maxDim.
int scaledW = (int)(scale*inImage.getWidth(null));
int scaledH = (int)(scale*inImage.getHeight(null));
out.println("<p>getting size of new image</p>");

// Create an image buffer in
//which to paint on.
//BufferedImage outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
PJABufferedImage outImage = new PJABufferedImage(scaledW, scaledH, PJABufferedImage.TYPE_INT_RGB);



// Set the scale.
AffineTransform tx = new AffineTransform();
out.println("<p>setting scale</p>");

// If the image is smaller than the desired image size,
// don't bother scaling.
if (scale < 1.0d)
{
tx.scale(scale, scale);
out.println("<p>image too small to need scaling</p>");
}

// Paint image.
Graphics2D g2d = outImage.createGraphics();
/* IT ALSO WON'T DO THIS PART */

g2d.drawImage((java.awt.Image)inImage, tx, null);
// g2d.drawImage(inImage, tx, null); // original
out.println("<p>g2d.dispose()</p>");
g2d.dispose();

out.println("<p>paint image</p>");
// JPEG-encode the image and write to file.
OutputStream os = new FileOutputStream(thumb);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
encoder.encode(outImage);
os.close();
out.println("<p>encode the image and write to file</p>");
}
catch (IOException e) {
out.println("<p>" + e.getMessage() + "</p>");
out.println("<p>failed to encode image and write to file</p>");
}
// catch (Exception e) {
// out.println("<p>" + e.getMessage() + "</p>");
// }
out.println("<p>end of createThumbnail function</p>");
}
---
Catriona


Home pageFind It!ContactTop

© Copyrights 1997-2014 eTeks - All rights reserved

PJAPJA documentation