JavaでGif画像を作成する際に透過色を設定する
この前のJavaでgifを作成する際に透過色を設定する方法メモ
TYPE_INT_RGB を TYPE_BYTE_INDEXED へ
buffer = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED);
transparentColorFlag を FALSE から TRUE へ
node.setAttribute("transparentColorFlag", "TRUE");
あとは透過したいところに、
int transcolor = buffer.getColorModel().getRGB(transColorIndex);
buffer.setRGB(0, 0, transcolor);
等すれば良い。
カラーパレットって定義できるのかな?
CentOS net-snmp の設定
yum install net-snmp net-snmp-utils
/etc/snmp/snmpd.conf
com2sec ${network} 192.168.0.0/16 ${public}
group local_group v1 ${network}
group local_group v2c ${network}
group local_group usm ${network}view all included .1 80
access local_group "" any noauth exact all none all
#特定のプロセスの監視を行いたい場合
#proc httpd
#proc lighttpdauthtrapenable 1
trapcommunity ${public}trap2sink observer ${public}
trapsink observer ${public}
informsink observer ${public}linkUpDownNotifications yes
createUser _internal MD5 "publicpassword"
iquerySecName _internal
rouser _internal#例えばこんな感じ。
monitor -u _internal -r 10 -o prNames -o prErrMessage "<-- procTable -->" prErrorFlag != 0
monitor -u _internal -r 30 -o memErrorName -o memSwapErrorMsg "<-- memory -->" memSwapError != 0
monitor -u _internal -r 30 -o extNames -o extOutput "<-- extTable -->" extResult != 0
monitor -u _internal -r 30 -o dskPath -o dskErrorMsg "<-- dskTable -->" dskErrorFlag != 0
monitor -u _internal -r 30 -o laNames -o laErrMessage "<-- laTable -->" laErrorFlag != 0
monitor -u _internal -r 30 -o fileName -o fileErrorMsg "<-- fileTable -->" fileErrorFlag != 0
monitor -u _internal -r 60 -e linkUpTrap "<-- Generate linkUp -->" ifOperStatus != 2
monitor -u _internal -r 60 -e linkDownTrap "<-- Generate linkDown -->" ifOperStatus == 2
#monitor -u _internal -r 30 -o hrSWRunName "<-- high process memory -->" hrSWRunPerfMem > 1000000
/etc/hostsにobserver(trap先のホスト)を記述しておく。
/etc/snmp/snmptrapd.conf
hostname : observerauthCommunity log,execute,net public
traphandle default /usr/bin/logger
ftpのコマンドに関する備忘録
ftp {hostname} #ftp -s:{cmdFile} {hostname}
>lcd c:/tmp/
>cd /files/>binary
>mget ${downloadFiles}*>bye
余談
FTPでAS400に接続した場合にbinaryモードでないとftpが無限ループする・・?→ WRKACTJOB>無理矢理終了
SAVFをローカルにダウンロードしたい場合は、
>get QTEMP/${LIBNAME} C:/tmp/${LIBNAME}.SAVF
みたいな感じでやるとすんなり落ちてくる。
逆にアップロードする場合は
>put c:/tmp/${LIBNAME}.SAVF QTEMP/${LIBNAME}
JavaでGifアニメーション
public static BufferedImage buffer;
int width = 100;
int height = 12;
int MAX_PAGE = 12;
private void execute() {
Iterator it = ImageIO.getImageWritersByFormatName("gif");
ImageWriter iw = it.hasNext() ? (ImageWriter) it.next() : null;
File outfile = new File("R:/sample.gif");
try {
buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
IIOMetadata meta = iw.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(buffer), null);
String format = meta.getNativeMetadataFormatName();
IIOMetadataNode root = (IIOMetadataNode)meta.getAsTree(format);
int count = 0;
byte[] data = {
0x01,
(byte)((count >> 0) & 0xFF),
(byte)((count >> 8) & 0xFF)
};
IIOMetadataNode list = new IIOMetadataNode("ApplicationExtensions");
IIOMetadataNode node = new IIOMetadataNode("ApplicationExtension");
node.setAttribute("applicationID", "NETSCAPE");
node.setAttribute("authenticationCode", "2.0");
node.setUserObject(data);
list.appendChild(node);
root.appendChild(list);node = new IIOMetadataNode("GraphicControlExtension");
node.setAttribute("disposalMethod", "none");
node.setAttribute("userInputFlag", "FALSE");
node.setAttribute("transparentColorFlag", "FALSE");
node.setAttribute("delayTime", "15");
node.setAttribute("transparentColorIndex", "0");
root.appendChild(node);
meta.setFromTree(format, root);
ImageOutputStream ios = ImageIO.createImageOutputStream(outfile);
iw.setOutput(ios);
iw.prepareWriteSequence(meta);
for (int i=0;i< MAX_PAGE; i++){
buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = buffer.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.red);
Integer s = (int) (Math.random() * 100000000);
g.drawString(s.toString(), 0, 12);
iw.writeToSequence(new IIOImage(buffer, null, meta), null);
}
iw.endWriteSequence();
} catch (IOException ex) {
ex.printStackTrace();
}
}
正直ヘッダ部分についてはあまり分かっていません。
細かいことはともかく感じだけ掴めたらいいかな、と。
JavaでPNG画像作成
private int x = 100;
private int y = 12;private void execute(String string) throws IOException {
BufferedImage im = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);
Graphics g = im.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, im.getWidth(), im.getHeight());
g.setColor(Color.black);
g.drawString(string, 0, 10);
im.flush();ByteArrayOutputStream bos = new ByteArrayOutputStream();
BufferedOutputStream os = new BufferedOutputStream(bos);
ImageIO.write(im, "png", os);
//output
FileOutputStream fos=new FileOutputStream("R:/test.png");
fos.write(bos.toByteArray());
fos.close();
}
とりあえず引数の文字列を画像にするだけだけど、さくっとできた。