#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JPEG; my $file = "zen16.jpg"; my $mw = Tk::MainWindow->new; my $can = $mw->Canvas( -width => 320, -height => 240 )->pack(); # if you are pulling your image from data (inline base64encoded string # you may need to specify -format #my $img = $mw->Photo( -data => $data, -format => 'jpeg' ); my $img = $mw->Photo( -file => $file); $can->createImage( 0, 0, -image => $img, -anchor => 'nw' ); my $red = $can->createRectangle(0, 20, 50, 75, -fill => 'red'); $can->Tk::bind("", [ \&print_xy, Ev('x'), Ev('y') ]); MainLoop(); sub print_xy { # print "@_\n"; my ($canv, $x, $y) = @_; print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\n"; printf "%6.6X\n", $img->get($canv->canvasx($x), $canv->canvasy($y) ); }