JAI - 旋轉效果 ( rotate )
public class JAITester {
private static final float CENTRAL_X = 45;
private static final float CENTRAL_Y = 45;
private static final float DEGREES = 45;
private static final String IMG_FILE_1 = "test1.jpg";
private PlanarImage doRotate(PlanarImage imageToCrop) {
float angle = (float) Math.toRadians(DEGREES);
ParameterBlock rotateParam = new ParameterBlock();
rotateParam.addSource(imageToCrop);
rotateParam.add(CENTRAL_X);
rotateParam.add(CENTRAL_Y);
rotateParam.add( angle );
rotateParam.add( new InterpolationBilinear() );
return JAI.create( "rotate", rotateParam );
}
/**
* http://forums.java.net/jive/message.jspa?messageID=221209
* this gets rid of exception for not using native acceleration */
static {
System.setProperty("com.sun.media.jai.disableMediaLib", "true");
}
public static void main(String[] args) {
JAITester test = new JAITester();
test.test();
}
private void test() {
PlanarImage input = JAI.create("fileload", IMG_FILE_1);
JPanel jPanelMain = new JPanel(new MigLayout("", "grow", "grow"));
jPanelMain.add(new JScrollPane(new DisplayJAI(input)), "grow");
jPanelMain.add(new JScrollPane(new DisplayJAI(doRotate(input))), "grow");
show(jPanelMain);
}
private void show(JComponent comp) {
JFrame f = new JFrame();
f.setLocation(50, 50);
f.setPreferredSize(new Dimension(800, 600));
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(comp);
f.pack();
f.setVisible(true);
}
}
Posted at 12:30上午 八月 13, 2008 by shooeugenesea in Java Image | 迴響[0]