[racket] Using 2htdp/image with racket-gui

From: Andrew Mauer-Oats (maueroats at gmail.com)
Date: Thu Mar 19 22:53:12 EDT 2015

Thanks. Yes, they want to (say) draw a solid green circle next to the name
of someone who has been active in the last five minutes. As I understand
it, they followed the GUI Toolkit intro and arrived at the point where they
have a canvas% with the on-paint method specified in its constructor. The
on-paint method then needs to draw the green circle. They are familiar with
(circle 20 "solid" "green"), so they just want to do the equivalent of
(place-image green-circle x y ?dc?).

I think the image->bitmap function Alexander provided looks like what they
need, and then they can use the draw-bitmap message.

I didn't know how to pull the functions from different packages to make
them usable one file.

Thanks for the help.

Andrew


Andrew Mauer-Oats
Mathematics Ph.D.
Chicago Public Schools: Whitney Young

On Thu, Mar 19, 2015 at 8:15 PM, Alexander D. Knauth <alexander at knauth.org>
wrote:

> Here’s one way, if you mean a bitmap% object:
>
> #lang racket/base
>
> (provide image->bitmap)
>
> (require racket/class
>          (only-in racket/draw make-bitmap bitmap-dc%)
>          (only-in 2htdp/image image-width image-height)
>          (only-in mrlib/image-core render-image))
>
> (define (image->bitmap image)
>   (let* ([width (image-width image)]
>          [height (image-height image)]
>          [bm (make-bitmap width height)]
>          [dc (make-object bitmap-dc% bm)])
>     (send dc clear)
>     (render-image image dc 0 0)
>     bm))
>
>
> On Mar 19, 2015, at 7:05 PM, Robby Findler <robby at eecs.northwestern.edu>
> wrote:
>
> > When you say "bitmap" do you mean "bitmap% object"? And if so, why do
> > they want to do that? If not, do you mean something else?
> >
> > Robby
> >
> >
> > On Thu, Mar 19, 2015 at 5:24 PM, Andrew Mauer-Oats <maueroats at gmail.com>
> wrote:
> >> Is there a public way to change an image created using the 2htdp/image
> >> library into a bitmap?
> >>
> >> My students are used to those functions and it would be easier for some
> of
> >> them to go and build the GUI they want if they didn't have to change
> over to
> >> explicitly using drawing contexts.
> >>
> >> I have looked at the source for mrlib/image-core,
> 2htdp/private/image-more,
> >> and 2htdp/image. It looks like no exported functions can change an
> image to
> >> a bitmap.
> >>
> >> The only thing they want to do is be able to render an image onto a dc.
> >> Presumably the render-image function would do that, were it exported.
> >>
> >> What should I do?
> >>
> >> Thanks for your help,
> >>
> >> Andrew Mauer-Oats
> >> Mathematics Ph.D.
> >> Chicago Public Schools: Whitney Young
> >>
> >> ____________________
> >>  Racket Users list:
> >>  http://lists.racket-lang.org/users
> >>
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150319/0ee04b6e/attachment.html>

Posted on the users mailing list.