0

saveFrame()controlp5 で作成された controlWindow からフレームを記録するために使用したいと思います。デフォルトsaveFrame()では、スケッチのメイン ウィンドウのみを記録します。どのウィンドウsaveFrame()からプルするかを指定する方法はありますか?

フレームごとに controlWindow に描画されたバッファを抽出する別の方法はありますか?

4

2 に答える 2

0

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");
于 2012-07-27T00:40:24.363 に答える
0

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

于 2012-07-20T15:54:11.537 に答える