dominoExperts.com - Powered by Domino 8.5.2 Domino Accelerator Pack
- Cache, Combine, JS-Minify and Compress content
Lotus Triple Search DominoExperts + Blogs + R8 forum
dominoExperts.com -> Script vault -> Java

 Thumbnails in domino


dicklarssonPost date: 2007-03-01 15:47
 

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();
        }
    }
}


Fredrik StöckelPost date: 2007-03-03 12:36

Nice example Dick!


Tomas NielsenPost date: 2007-03-07 21:33

Cool!


Jonas IsraelssonPost date: 2007-03-11 14:05

Nicely done Dick!




RSS feed
Subscribe to Forum

Share this page

Top posters
Tomas Nielsen212
Joacim Boive27
Fredrik Stöckel27
Danne14
Niklas Waller13
Kenneth Haggman11
Bryan Kuhn10
Daniel Lehtihet9
Jonas Israelsson8
dm997