1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| import com.cycling74.max.*;
import com.cycling74.jitter.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
/**
* Creates a graph in a BufferedImage and then pops it into a
* JittterMatrix for output in Max-Msp.
* (By sending "outputDrawing" message to the max-msp "bufferedimage_test" object)
*/
public class bufferedimage_test extends MaxObject {
public bufferedimage_test(Atom[] args) {
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});
}
public void outputDrawing() {
// the drawing code is probably very low impact, but it's still a
// good idea to wrap it in a Thread to free up processor time.
( new Thread() {
public void run() {
BufferedImage bim = bakePieGraph();
JitterMatrix jim = new JitterMatrix(bim);
outlet(0, "jit_matrix", jim.getName());
}
}).start();
}
public BufferedImage bakePieGraph() {
Frame theframe = new Frame ();
theframe.addNotify ();
Image myImage = theframe.createImage(320,200);
Graphics2D gc = (Graphics2D)myImage.getGraphics ();
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
gc.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
gc.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
gc.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
// c'est cette boucle-ci qui met une seconde a s'exécuter :
for ( int i = 0; i<450000 ;i++) {
Shape ligne = new Line2D.Float( 10, 10,20,25 );
gc.draw(ligne);
}
return makeBufferedImage(myImage);
}
public static BufferedImage makeBufferedImage(Image image) {
BufferedImage bufferedImage = new BufferedImage(
image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bufferedImage.createGraphics();
g2.drawImage(image, null, null);
return bufferedImage;
}
} |
Partager