<div>Thanks for your hints, Matthias,</div>
<div><br>I read the document, and I think I can get a solution from </div>
<div>frame% -> editor-canvas% -> image-snip% -> get-bitmap <br> </div>
<div>I think I still need learn and practice more, to know better about the canvas, editor, pasteboard, editor-canvas etc.</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">Now it's time to use the help desk and to search for terms like<br>canvas, editor, pasteboard, editor-canvas and just chase the links.
<br>Everything is hyperlinked, so you can find your way around easily,<br>not that this means everything is easy. -- Matthias<br><br><br><br>On Dec 18, 2007, at 10:00 PM, Lian DanHui wrote:<br><br>> Hello Matthias,<br>
><br>> Really appreciate your answer provided! It is very clear, and I get<br>> it.<br>><br>> And I think of other scenarios:<br>> One possible scene, if the picture is scaled up or down on the canvas?<br>
> One possible scene, if the user do some changes on the canvas, and<br>> then click to get the pixel color?<br>><br>> I think for the first scene, I still can use the method you<br>> provided. But for second case, I don't know how.
<br>> I wonder if I can get the bitmap-dc% from Canvas dc, or something<br>> similar like that.<br>> Can I get the pixels matrix of the current canvas operated?<br>><br>> thanks & regards,<br>> Linda Lian
<br>><br>> On 12/19/07, Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> wrote:<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>><br><br></blockquote></div><br>