Saturday, June 20, 2009

im4javaで英文字列を描画する

im4javaで英文字列を描画するには、以下のコードを実行します。


import java.util.*;
import org.im4java.core.*;
import org.im4java.process.*;

// im4java-0.98.0-bin.tar.bz2を解凍してim4java-0.98.0.jarはclasspathに通す
public class Im4java26
{
public static void main(String args[])
throws Exception
{
try
{
// ConvertCmd convert = new ConvertCmd();
ImageCommand convert = new WindowsConvertCmd();

IMOperation op = new IMOperation();
op.size(200, 200);
op.addImage("xc:white");
op.font("Tahoma");
op.pointsize(50);
op.gravity("center");
op.fill("#7799ff");
op.draw("text 0,0 'im4java'");
op.addImage("sample1120a.png");
convert.run(op);
}
catch(CommandException cex)
{
System.out.println(cex.getErrorText());
cex.printStackTrace();
}
}

// im4java 0.98
static class WindowsConvertCmd extends ImageCommand
{
public WindowsConvertCmd()
{
setCommand("cmd");
setCommand("/c");
setCommand("convert");
/* another way
setCommand("C:\\Program Files\\ImageMagick-6.4.9-Q16\\convert");
*/
}
}
}


出力画像(sample1120a.png)
im4javaで描画した英文字列

関連情報
im4javaのまとめ

No comments: