cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert java code to Portal

Former Member
0 Kudos

Hello,

I have java code which resizes the image. I want to know whether the code would work fine in PDK.if not what is the chanes to be done to the attached code.

import com.sun.image.codec.jpeg.*;

import java.awt.*;

import java.awt.image.*;

import java.io.*;

public class Thumbnail1

{

public static void main(String[] args) throws Exception

{

if (args.length != 4)

{

System.err.println("Usage: java Thumbnail INFILE " + "OUTFILE WIDTH HEIGHT ");

System.exit(1);

}

// load image from INFILE

Image image = Toolkit.getDefaultToolkit().getImage(args[0]);

MediaTracker mediaTracker = new MediaTracker(new Container());

mediaTracker.addImage(image, 0);

mediaTracker.waitForID(0);

// determine thumbnail size from WIDTH and HEIGHT

int newImageWidth = Integer.parseInt(args[2]);

int newImageHeight = Integer.parseInt(args[3]);

double newImageRatio = (double)newImageWidth / (double)newImageHeight;

int oldImageWidth = image.getWidth(null);

int oldImageHeight = image.getHeight(null);

double oldImageRatio = (double)oldImageWidth / (double)oldImageHeight;

if (newImageRatio > oldImageRatio)

{

newImageWidth = (int)(newImageHeight * oldImageRatio);

}

else

{

newImageHeight = (int)(newImageWidth / oldImageRatio);

}

// draw original image to thumbnail image object and

// scale it to the new size on-the-fly

BufferedImage newThumbImage = new BufferedImage(newImageWidth, newImageHeight, BufferedImage.TYPE_INT_RGB);

Graphics2D graphics2D =newThumbImage.createGraphics();

graphics2D.drawImage(image, 0, 0, newImageWidth, newImageHeight, null);

// save thumbnail image to OUTFILE

BufferedOutputStream outFile = new BufferedOutputStream(new FileOutputStream(args[1]));

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outFile);

JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(newThumbImage);

encoder.setJPEGEncodeParam(param);

encoder.encode(newThumbImage);

outFile.close();

System.out.println("Successfully Saved.");

System.exit(0);

}

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi ramalingam,

i dont know how well u can access the java applications from portal. i am sending u the following link just refer that.

http://help.sap.com/saphelp_nw04s/helpdata/en/88/bdfc3f48ecc742e10000000a1550b0/frameset.htm

but i am very sure u can access j2ee applications. see the following link.

http://help.sap.com/saphelp_nw04s/helpdata/en/88/bdfc3f48ecc742e10000000a1550b0/frameset.htm

if u find anything regarding access of java applications just inform me.it will be a good learning curve for me.

i think u can display your java class as web services and consume it in portal..

regards,

purushothaman.

Message was edited by: purushothaman vyasarao

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

i think the problem could be with portalapp.xml, post it so that we can find the error.