我正在學習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