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

From: Alexander D. Knauth (alexander at knauth.org)
Date: Thu Mar 19 21:15:56 EDT 2015

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



Posted on the users mailing list.