<div>Hello Matthias,</div>
<div> </div>
<div>Really appreciate your answer provided! It is very clear, and I get it.</div>
<div> </div>
<div>And I think of other scenarios:</div>
<div>One possible scene, if the picture is scaled up or down on the canvas?</div>
<div>One possible scene, if the user do some changes on the canvas, and then click to get the pixel color?<br> </div>
<div>I think for the first scene, I still can use the method you provided. But for second case, I don't know how.</div>
<div>I wonder if I can get the bitmap-dc% from Canvas dc, or something similar like that. </div>
<div>Can I get the pixels matrix of the current canvas operated?</div>
<div> </div>
<div>thanks & regards,</div>
<div>Linda Lian</div>
<div> </div>
<div><span class="gmail_quote">On 12/19/07, <b class="gmail_sendername">Matthias Felleisen</b> <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>On Dec 18, 2007, at 5:08 AM, Lian DanHui wrote:<br><br>> Hello,<br>><br>> I want to implement something like this:
<br>> 1. Display a picture in a Canvas on a Frame;<br>> 2. User can click on the picture;<br>> 3. I want to get the color of the pixel that user clicked;<br>><br>> For Canvas object, Using what method or what strategy, that I can
<br>> get the pixel info?<br>> Thanks a lot for the help!<br><br>Here is a literal translation of your request into the most basic<br>language. If you are a student and using world.ss, it is simpler. --<br>Matthias<br>
<br>#lang scheme/gui<br><br>;; obtain a bitmap and stick it into a bitmap dc<br>(define plt<br> (make-object bitmap% (build-path (collection-path "icons")<br>"plt.gif")))<br>(define bm<br> (new bitmap-dc% [bitmap plt]))
<br><br>;; --- set up a frame with a canvas in which to display this image<br>(define frame<br> (new frame% [label "Test for Linda"]<br> [width (send plt get-width)] [height (send plt get-height)]))<br><br>
(define canvas (new<br> ;; --- create a class on the fly that overrides the<br>callback for<br> ;; --- mouse events in a canvas; you could name it,<br>if needed<br> (class canvas%
<br> ;; Event -> Void<br> ;; act on each mouse event<br> (define/override (on-event e)<br> (define kind (send e button-down?))<br> (define x (send e get-x))
<br> (define y (send e get-y))<br> (define c (new color%))<br> (when kind<br> (if (send bm get-pixel x y c)<br> (printf "color is ~s ~s ~s\n"
<br> (send c red) (send c green) (send<br>c blue))<br> (printf "no color"))))<br> (super-new))<br> ;;--- provide a frame and a paint method for
<br>displaying plt.gif<br> [parent frame]<br> [paint-callback (lambda (e dc) (send dc draw-bitmap<br>plt 0 0))]))<br><br>;; --- run program run<br>(send frame show #t)<br></blockquote></div><br>