import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
import java.awt.geom.*;
public class JPGImage
{
public JPGImage(String srcFileName,String destFileName,int
thumbNailSize) throws Exception
{
// Read in original image to create thumbnail from
File inFile = new File(srcFileName);
BufferedImage bufferedImage = ImageIO.read(inFile);
bufferedImage.flush();
// Calculate scale so image fits in a square area of thumbNailSize
int imageWidth = bufferedImage.getWidth();
int imageHeight = bufferedImage.getHeight();
int componentWidth = thumbNailSize;
int componentHeight = thumbNailSize;
double scale = -1;
if ( imageWidth == componentWidth && imageHeight ==
componentHeight){
scale = 1;
}
else if ( imageWidth <= componentWidth && imageHeight <=
componentHeight)
{
double heightScale = ((double)componentWidth) / ((double)
imageWidth);
double widthScale = ((double)componentHeight) / ((double)
imageHeight);
if ( heightScale < widthScale ) scale = heightScale;
else scale = widthScale;
}
else if ( imageWidth > componentWidth && imageHeight <=
componentHeight)
{
double heightScale = ((double)componentWidth) / ((double)
imageWidth);
scale = heightScale;
}
else if ( imageWidth <= componentWidth && imageHeight >
componentHeight)
{
double widthScale = ((double)componentHeight) / ((double)
imageHeight);
scale = widthScale;
}
else
{
double heightScale = ((double)componentWidth) / ((double)
imageWidth);
int scaledHeight = (int)(((double)imageHeight) *
heightScale);
double widthScale = ((double)componentHeight) / ((double)
imageHeight);
int scaledWidth = (int)(((double)imageWidth) * widthScale);
if ( scaledWidth <= componentWidth ) scale = widthScale;
else scale = heightScale;
}
// Now create thumbnail
AffineTransform affineTransform = AffineTransform.getScaleInstance
(scale,scale);
AffineTransformOp affineTransformOp = new AffineTransformOp
(affineTransform,null);
BufferedImage scaledBufferedImage = affineTransformOp.filter
(bufferedImage,null);
int scaledWidth = scaledBufferedImage.getWidth();
int scaledHeight = scaledBufferedImage.getHeight();
int expectedWidth = (int)(imageWidth * scale);
int expectedHeight = (int)(imageHeight * scale);
if ( scaledWidth > expectedWidth || scaledHeight > expectedHeight )
scaledBufferedImage = scaledBufferedImage.getSubimage
(0,0,expectedWidth,expectedHeight);
// Now write out scaled image to file
ImageIO.write(scaledBufferedImage,"JPG",new File(destFileName));
}
public static void main(String[] args)
{
try
{
int size = 800;
//size = Integer.parseInt(args[2]);
String cart;
cart = args[0];
File f = new File(cart);
String list[] = f.list();
for (int i = 0; i < list.length; i++)
---> JPGImage jpgImage = new JPGImage(list[i],list[i],size);
}
catch (Exception exception)
{
System.out.println("Attenzione errore:" + exception);
}
}// fine main
}
Alla riga contrassegnata in rosso in fase di compilazione mi dice:
not a statement.Qualche suggerimento?
grazie