Friday, March 06, 2009

groovyで画像を角丸四角にする

groovyで画像を角丸四角にするには、以下のコードを実行します。


import groovy.swing.j2d.*

def gr = new GraphicsRenderer()
gr.renderToFile("sample822a.png", 200, 200){
antialias("on")
rect( x: 10, y: 10, width: 180, height: 180,
arcWidth: 20, arcHeight:20, borderColor: no){
texturePaint(x: 0, y: 0, file: 'sf.jpg' )
}
}


元画像(sf.jpg)


出力画像(sample822a.png)
groovyで角丸四角にした画像

動作環境
Groovy1.6.0 Beta2, JDK1.6 Update11

関連項目
groovyで画像に着色する

No comments: