2012-07-19 57 views

回答

0

Java中的Windows通常是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

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");