|
Run this agent code in Domino 7
The agent downloads a image resource from the web and creates a thumbnail image.
import lotus.domino.*;
import javax.imageio.*; //used for images
import java.awt.*;
import java.awt.image.*;
import java.net.*;
import java.io.*;
public class JavaAgent extends AgentBase {
//Author, Dick Larsson, dick.larsson@ekakan.com +46(0)706 - 33 23 68
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Label label = new Label(); //we need a GUI component as ImageObserver and other stuff
//SET MAX WIDTH OR HEIGHT
int maxWidth = 70;
int maxHeight = 120;
//Load the org image from an URL
Image image = null;
URL url = new URL("http://www.ekakan.com/www/web.nsf/peter_staende_w200.jpg");
image = ImageIO.read(url);
float orgWidth = (float) image.getWidth(label);
float orgHeight = (float) image.getHeight(label);
//DECREASE THE SIZE BY 10 PERCENT EACH LOOP TO FIND MAX WIDTH OR HEIGHT
while(orgWidth >= maxWidth || (orgHeight >= maxHeight)) {
orgWidth = orgWidth * 0.9f;
orgHeight = orgHeight * 0.9f;
}
//CREATE A NEW IN MEMORY IMAGE
BufferedImage thumbImage = new BufferedImage((int) orgWidth, (int) orgHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, (int) orgWidth, (int) orgHeight, null);
//SAVE THE FILE ON DISK IN PNG FORMAT
File file = new File("c:/newimage.png");
ImageIO.write(thumbImage, "png", file);
} catch(Exception e) {
e.printStackTrace();
}
}
}
|