Re: Get Tk::Canvas pixels

Ala Qumsieh <[email protected]>
Newsgroups gmane.comp.lang.perl.tk
Message-ID <[email protected]>
I have toyed before with code that checks every
location on a Canvas, and finds what the topmost item
is, and put()s the fill color of that item in the
corresponding location in a Photo object. Something
like this:

  use Tk 804;
  use Tk::PNG;

  sub canv2PNG {
    my $c = shift;   # the canvas
    my $outF = 'out.png';
    $mw->Busy;

    my $p = $mw->Photo(-height => $c->height,
		           -width  => $c->width,
		           -format => 'png',
		          );

    for my $x (0 .. $c->width - 1) {
      for my $y (0 .. $c->height - 1) {
        my @i = $c->find(overlapping => $x, $y, $x,
$y);
        defined $i[0] or next;

        my $tag = $i[-1];
        my $col = $c->itemcget($tag, '-fill');
        $p->put([$col], -to => $x, $y);
      }
    }

    $p->write($outF, -format => 'png');
    $mw->Unbusy;
  }

But it has some severe limitations:

- Only handles simple items: Lines, Rectangles,
Polygons and Ovals. No Text.
- Does not output the -outline color.
- Does not handle transparency and stipples.
- Is somewhat slow.

I'm not sure how to address those issues.

If your application can live with them, then that
might be a good solution.

--Ala


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.