saveFrame()
controlp5 で作成された controlWindow からフレームを記録するために使用したいと思います。デフォルトsaveFrame()
では、スケッチのメイン ウィンドウのみを記録します。どのウィンドウsaveFrame()
からプルするかを指定する方法はありますか?
フレームごとに controlWindow に描画されたバッファを抽出する別の方法はありますか?
saveFrame()
controlp5 で作成された controlWindow からフレームを記録するために使用したいと思います。デフォルトsaveFrame()
では、スケッチのメイン ウィンドウのみを記録します。どのウィンドウsaveFrame()
からプルするかを指定する方法はありますか?
フレームごとに controlWindow に描画されたバッファを抽出する別の方法はありますか?
PApplet.saveImage()
は基本的に のラッパーPImage.save()
です。画面の一部だけをキャプチャする場合は、 にレンダリングしてから をPImage()
呼び出す必要がありますPImage.save()
。 PImage.save()
ただし、独自のファイル名を指定する必要があります。自動インクリメントは行われませんPApplet.saveImage()
。
ControlP5 コンテンツを別のバッファー (PImage) に描画するのは簡単ではないように見えますが、メインのグラフィック コンテキストから任意の四角形を取得して保存することはできます。
PImage screengrab = createImage(controlWindow.width, controlWindow.height, RGB);
screengrab.loadPixels();
loadPixels();
for (int i=0; i<screengrab.width*screengrab.height; i++) {
// loop thru pixels and copy into screengrab.pixels...
// i'll leave the math here as a fun exercise for you.
}
screengrab.updatePixels();
updatePixels();
screengrab.save("screengrab.png");
Java のウィンドウは通常JFramesです。私はテストしていませんが、次のようなことができるはずです:
import java.awt.Component;
import java.awt.image.BufferedImage;
//get to the java.awt.Component
Component window = yourP5ControlWindow.component();
//make a BufferedImage to store pixels into
BufferedImage snapshot = new BufferedImage(window.getWidth(),window.getHeight(),BufferedImage.TYPE_INT_RGB);
//take a snapshot
window.paint( snapshot.getGraphics() );
//create a PImage out of the BufferedImage
PImage image = new PImage(snapshot);
//save,etc.
image.save("yourComponent.png");
HTH