I have a Perl script that generates a display window
containing various informational text in varying
colors all on a black background. What I need to do
is to be able to "screen capture" this display and
save it as an image file (JPEG, BMP, whatever).
Various suggestions on the web talk about using
Tk::WinPhoto, but I'm not using X (I'm on Windows XP)
and WinPhoto doesn't exist in my Tk directory.
Attempts to even try it using the following snippet
(with Tk::Photo and Tk::JPEG)
$image = $mw->Photo(-format => 'Window', -data => oct($JTADisplay->id)); $filename = 'myimage.jpg'; $image->write($filename, -format => 'JPEG');
gives me the following error (understandably):
Tk::Error: image format "Window" is not supported at C:/Perl/site/lib/Tk/Image.pm line 21.
So, if anybody can shed some light to this, I would be
most thankful. The following is another snippet of my
code if it helps:
Thanks in advance.$mw = MainWindow->new(-background => 'black'); $mw->geometry('+0+0'); $mw->title("My Display"); $f = $mw->Frame(-background => 'black')->pack; $f->Label(-text => 'PROJECTION', -foreground => 'white', -background => 'black')-> grid(-row => 1, -column => 1, -columnspan => 3, -sticky => ' +w'); for ($i = 0; $i <= 5; $i++) { $f->Label(-text => $i, -foreground => 'white', -background => 'bla +ck')-> grid(-row => 1, -column => $i + 4, -sticky => 'nsew'); } $advisoryLabel = $f->Label(-textvariable => \$advisory, -foreground => $advisoryColor, -background => 'black')-> grid(-row => 2, -column => 1, -columnspan => 3 +, -sticky => 'w'); for ($i = 0; $i <= 5; $i++) { $JTALabel[$i] = $f->Label(-textvariable => \$JTA[$i + 1], -foreground => $JTAColor[$i + 1], -background => 'black')-> grid(-row => 2, -column => $i + 4, -sticky => 'nsew'); } $f->Label(-text => 'BREAKDOWN', -foreground => 'white', -background => 'black')->grid(-row => 3, -column => 1, -columnspan => 9, -sticky => 'nsew'); $f->Label(-text => 'ID', -foreground => 'white', -background => 'black')->grid(-row => 4, -column => 1, -sticky => 'w'); $f->Label(-text => 'TYPE', -foreground => 'white', -background => 'black')->grid(-row => 4, -column => 2, -sticky => 'w'); for ($i = 0; $i <= 5; $i++) { $f->Label(-text => $i, -foreground => 'white', -background => 'bla +ck')-> grid(-row => 4, -column => $i + 4, -sticky => 'nsew'); } foreach $name (keys %Domes) { $domeIndex = $Domes{$name}{dome}; $fRow = ($domeIndex * 2) + 6; $IDLabel[$domeIndex] = $f->Label(-text => $name, -foreground => 'green', -background => 'black')-> grid(-row => $fRow, -column => 1, -sticky => 'w'); $TypeLabel[$domeIndex] = $f->Label( -textvariable => \$Type[$domeIndex], -foreground => 'green', -background => 'black')-> grid(-row => $fRow, -column => 2, -sticky => 'w'); $f->Label(-text => 'PA:', -foreground => 'white', -background => 'black')-> grid(-row => $fRow, -column => 3, -sticky => 'w'); $f->Label(-text => 'RA:', -foreground => 'white', -background => 'black')-> grid(-row => $fRow + 1, -column => 3, -sticky => 'w'); for ($i = 0; $i <= 5; $i++) { $JABLabel[$domeIndex][0][$i] = $f->Label( -textvariable => \$JABText[$domeIndex][0][$i + 1], -foreground => 'green', -background => 'black')-> grid(-row => $fRow, -column => $i + 4, -sticky => 'nsew'); $JABLabel[$domeIndex][1][$i] = $f->Label( -textvariable => \$JABText[$domeIndex][1][$i + 1], -foreground => 'green', -background => 'black')-> grid(-row => $fRow + 1, -column => $i + 4, -sticky => 'nse +w'); } } # create the menus $menuBar = $mw->Menu; $mw->configure(-menu => $menuBar); $file = $menuBar->cascade(-label => 'File', -tearoff => 0); $file->command(-label => 'New', -command => \&newDemo); $file->command(-label => 'Save Display', -command => \&saveDisplay); $file->separator; $file->command(-label => 'Quit', -command => \&closeWindow); $action = $menuBar->cascade(-label => 'Scenario', -tearoff => 0); $action->command(-label => 'Start Demo', -command => \&JTAMain); $action->command(-label => 'Stop Demo', -command => sub {$stopDemo = 1 +}); MainLoop(); sub saveDisplay { $image = $mw->Photo(-format => 'Window', -data => oct($JTADisplay->id)); $filename = 'myimage.jpg'; $image->write($filename, -format => 'JPEG'); }
In reply to Saving Contents of Perl/Tk Display to a File by baklobsters
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |