import javax.swing.*;
import java.awt.*;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;
import java.io.*;
public class HTMLImageGenerator implements ImageObserver
{
private static String _bgColor = "ffffff";
private static String LINE_SEP = System.getProperty("line.separator");
private final static String COLOR_BEGIN_TAG = "= 3)
{
String chooseGray = args[2];
if (chooseGray.equalsIgnoreCase("true"))
{
gray = true;
}
}
if (args.length == 4)
{
_words = readInFile(args[3]);
String x = new String(_words);
x = x.replace((char) 13, (char) 32);
x = x.replace((char) 10, (char) 32);
x = x.replace((char) 9, (char) 32);
_words = x.getBytes();
}
HTMLImageGenerator gen = new HTMLImageGenerator(image, fileName, gray);
System.exit(0);
}
private static void bailOut()
{
System.out.println(USEAGE);
System.exit(-1);
}
private static void bailOut(Exception ex)
{
System.out.println(USEAGE + "Exception : \n" + ex);
System.exit(-1);
}
private static void bailOut(String error, Exception ex)
{
System.out.println(USEAGE + ": \n" +
error + "\n" +
"Exception : \n" + ex);
System.exit(-1);
}
public HTMLImageGenerator(String imageFileName, String fileName, boolean grayScale)
{
_grayScale = grayScale;
_output = new StringBuffer();
_baseImage = new ImageIcon(imageFileName).getImage();
_height = _baseImage.getHeight(this);
_width = _baseImage.getWidth(this);
if (_height <= 0 || _width <= 0)
{
bailOut("The file you entered :\""+fileName+"\" does not exist or is not a valid Image file.", new IllegalArgumentException("The file you entered does not exist"));
}
try
{
_outputStream = new FileOutputStream(new File(fileName));
_outputStream.write(getHeader().getBytes());
_filter = new GrayFilter(true, 40);
_output = processImage(_baseImage);
_outputStream.write(getFooter().getBytes());
}
catch(IOException ioe)
{
bailOut(ioe);
}
}
public HTMLImageGenerator(String fileName)
{
this(fileName, "c:\\test.htm", false);
}
private String getOutput()
{
return _output.toString();
}
private static String getHeader()
{
return "
| "; } private static String getFooter() { return " |