devdoc

Tuesday, October 18, 2005

Images

It would be nice if we could set the height and width to any image withot knowing anything about the image....


/*
* Ivan Pedrazas, Created on 18-Oct-2005
*
* (c) SWORD-UK 18-Oct-2005
* FILE: ImageAnalizer.java
*
* */
package com.sword.intranet.documentum.job;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.common.DfException;


public class ImageAnalizer {


private static final long serialVersionUID = 1L;
/** Logger for this class and subclasses */
protected static final Log logger = LogFactory.getLog(ImageAnalizer.class);

public static void analize(IDfSysObject sysObj){

ByteArrayInputStream bias = null;

try {
bias = sysObj.getContent();
BufferedImage image = ImageIO.read(bias);
setData(image,sysObj);
bias.close();
} catch (IOException e) {
logger.error(e.getMessage());
}catch (DfException e) {
logger.error(e.getMessage());
}

}

private static void setData(BufferedImage image,IDfSysObject sysObj){
boolean fSave = false;
try {
if(sysObj.hasAttr("cs_width")){
int width = image.getWidth();
if(width>0){
sysObj.setString("cs_width",Integer.toString(width));
fSave = true;
}
}
if(sysObj.hasAttr("cs_height")){
int height = image.getHeight();
if(height>0){
sysObj.setString("cs_height",Integer.toString(height));
fSave = true;
}
}
if(fSave){
sysObj.save();
}
} catch (DfException e) {
logger.error(e.getMessage());
}

}
}

0 Comments:

Post a Comment

<< Home