我正在学习tk并尝试调试我的脚本。我不知道我错过了什么将图像保存到文件中。感谢您的任何帮助perl,tk如何将此图像保存到文件中?
#!/tool/pandora64/bin/perl5.8.8.a
use Tk;
my ($size, $step) = (200, 10);
# Create MainWindow and configure:
my $mw = MainWindow->new;
$mw->configure(-width=>$size, -height=>$size);
$mw->resizable(0, 0); # not resizable in any direction
# Create and configure the canvas:
my $canvas = $mw->Canvas(-cursor=>"crosshair", -background=>"white",
-width=>$size, -height=>$size)->pack;
# Place objects on canvas:
$canvas->createRectangle($step, $step, $size-$step, $size-$step, -fill=>"red");
for(my $i=$step; $i<$size-$step; $i+=$step) {
my $val = 255*$i/$size;
my $color = sprintf("#%02x%02x%02x", $val, $val, $val);
$canvas->createRectangle($i, $i, $i+$step, $i+$step, -fill=>$color);
}
$canvas->postscript(-file=>"file_name.ps");
`convert file_name.ps file_name.jpeg`; # I can move this outside out of the script
exit 0;
当你运行上面的代码时会发生什么?有没有错误信息?有意想不到的输出吗? – 2012-01-09 18:27:06
它创建文件file_Name.ps和file_name.jpeg,当我查看file_name.jpeg,它什么也没有显示... – Gordon 2012-01-09 18:27:33
在反引号中的转换试图产生一个新的进程,并且你不检查是否成功。 – theglauber 2012-01-09 18:28:11