Hi all,

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:

$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'); }
Thanks in advance.

In reply to Saving Contents of Perl/Tk Display to a File by baklobsters

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.