小编tii*_*in4的帖子

将JPanel Graphics导出为.png或.gif或.jpg

我正在尝试使用Java开发某种绘画.

我有一个位于JPanel内的JComponent.

我已经可以在该JComponent中绘制线条和矩形.

现在,我如何将这些图纸导出为图像(png,gif,jpg)?

我试过这个:

BufferedImage b = new BufferedImage(1700,1100,BufferedImage.TYPE_INT_RGB);
this.print(getGraphics());
try{ImageIO.write(b,"png",new File("test.png"));}catch (Exception e) {}
Run Code Online (Sandbox Code Playgroud)

但这只会创建一个全黑的.png文件.

救命!!!

解决!!!

BufferedImage bi = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_ARGB); 
Graphics g = bi.createGraphics();
this.paint(g);  //this == JComponent
g.dispose();
try{ImageIO.write(bi,"png",new File("test.png"));}catch (Exception e) {}
Run Code Online (Sandbox Code Playgroud)

java export image jpanel

14
推荐指数
1
解决办法
2万
查看次数

如何安装Nokogiri Gem for Windows

我对nokogiri的宝石有这个问题:

无法打开库'C:\ Ruby187\lib\ruby​​\gems\1.8\gems \nokogiri-1.4.6-x86-mingw32\ext \nokogiri\libxml2.dll':未知

我读到我必须尝试1.5.0.beta3版本.但是,当我跑

C:\Users\t3en4>gem install nokogiri --pre
Fetching: nokogiri-1.5.0.beta.4.gem (100%)
ERROR:  Error installing nokogiri:
        The 'nokogiri' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

gem ruby-on-rails jruby nokogiri

6
推荐指数
2
解决办法
1万
查看次数

将元素添加到画布html5

可以在HTML5的画布中添加元素吗?

例如:

<canvas id="canvas2" width="650" height="850"> 
    <div class="draggable" class="ui-widget-content" width='100px' height='100px'>
       <textarea class="resizable" rows="2" cols="10" style="color: #FF0707; ">
        Example
       </textarea>
    </div>
</canvas> 
Run Code Online (Sandbox Code Playgroud)

这没有显示任何东西......但是,如果我把那个可拖动的div放在html中的任何其他元素中它可以工作......

我错过了什么?

谢谢.

html5 canvas

5
推荐指数
1
解决办法
1万
查看次数

如何在Windows上安装mysql2 gem

我正在使用DevKit和XAMPP,现在我必须执行以下命令:

gem install mysql2 -v 0.2.6 --platform=ruby -- --with-mysql-dir="x:\Prog
ram Files\mysql-5.5.11-winx64" --with-mysql-lib="x:\Program Files\mysql-5.5.11-winx64\lib" --with-my
sql-include="x:\Program Files\mysql-5.5.11-winx64\include" --without-opt-dir
Run Code Online (Sandbox Code Playgroud)

但是,XAMPP 在其MySQL目录中不包含libinclude文件夹.我应该指定什么呢?

谢谢

windows rubygems ruby-on-rails devkit

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

ruby-on-rails ×2

canvas ×1

devkit ×1

export ×1

gem ×1

html5 ×1

image ×1

java ×1

jpanel ×1

jruby ×1

nokogiri ×1

rubygems ×1

windows ×1