Version 4 of Get the color of the pixel under the cursor

Updated 2006-01-25 00:47:33

HJG I have some images on a canvas, and I want to get the color of the pixel under the cursor.

Right now, this works only for an image placed on the canvas a 0,0 :


  package require Img

  proc int x { expr int($x) }

  proc ShowPixel {x y i} {
    set c "- - -"
    catch { set c [$::img1 get $x $y] }
    wm title . "$x $y #$i : $c"
  }

  set fn gosmall.gif
  set img1 [image create photo -file $fn]

  pack [canvas .c]
  .c create image  0  0 -image $img1 -anchor nw -tag Copy1
  .c create image 80 80 -image $img1 -anchor nw -tag Copy2

  bind .c <Motion> { ShowPixel [int [%W canvasx %x]] [int [%W canvasy %y]] [%W find withtag current] }

The RGB-values of the pixel under the cursor are shown only for the first copy of the image...

I can query the coordinates of an item/image on the canvas with bbox (to adjust coordinates within the image vs. the screen-coordinates given by the cursor), but how do I pass the item (as opposed to its id) to the proc ShowPixel ?


Category Graphics - Category Image Processing