我有一个JPanel,我想添加我动态生成的JPEG和PNG图像.
到目前为止我在Swing教程中看到的所有示例,特别是在Swing示例中使用的ImageIcon是s.
我将这些图像生成为字节数组,并且它们通常比它们在示例中使用的常见图标大,为640x480.
编辑:仔细检查教程和API会显示您无法将ImageIcon直接添加到JPanel.相反,它们通过将图像设置为JLabel的图标来实现相同的效果.这感觉不对......
我试图将canvas元素保存为png图像.这是我的代码,但不幸的是,它不起作用:
import time
from selenium import webdriver
# From PIL import Imag.
driver = webdriver.Firefox()
driver.get('http://www.agar.io')
driver.maximize_window()
driver.find_element_by_id('freeCoins').click()
time.sleep(2)
# The part below does not seem to work properly.
driver.execute_script('function download_image(){var canvas = document.getElementByTagName("canvas");canvas.toBlob(function(blob) {saveAs(blob, "../images/output.png");}, "image/png");};')
Run Code Online (Sandbox Code Playgroud)
我想在Python中看到解决方案.我还希望在截图结束时看到一个不需要裁剪的解决方案.
我试图在Firefox浏览器代码中使用selenium webdriver 2.47.0版本中添加的WebElement#getScreenShotAs(OutputType.FILE)功能
public static void main(String[] args) throws IOException {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://automationpractice.com/index.php");
WebElement element=driver.findElement(By.cssSelector("a[title='Contact Us']"));
System.out.println(element.getText());
element.getScreenshotAs(OutputType.FILE);
File destination=new File("Image.png");
FileUtils.copyFile(null, destination);
}
Run Code Online (Sandbox Code Playgroud)
..但我得到以下异常:
Contact us
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Unrecognized command: GET /session/e796089b-1d64-4590-9157-a0716a57e399/screenshot/%7B4329461b-5e9c-4f8b-b589-ddc1af1d55a6%7D
Command duration or timeout: 16 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'mrunal-laptop', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=41.0.2, …Run Code Online (Sandbox Code Playgroud)