[plt-scheme] duplicate of a bitmap

From: Robby Findler (robby at cs.uchicago.edu)
Date: Thu Aug 24 16:50:08 EDT 2006

Probably you want to use a bitmap-dc%. Maybe not less complicated, but
more efficient (I didn't test the below, but those are the right method
names).

(define (copy-bitmap bitmap)
  (let* ([nb (make-object bitmap%
               (send bitmap get-width)
               (send bitmap get-height))]
         [bdc (make-object bitmap-dc% nb)])
    (send bdc clear)
    (send bdc draw-bitmap bitmap 0 0)
    (send bdc set-bitmap #f)
    nb))

Robby

At Thu, 24 Aug 2006 16:48:19 -0400, David Richards wrote:
> 
> What is the simplest way to make a duplicate of a bitmap?
> 
> Currently I do something like this (which seems overly complicated):
> 
> (let* ((_bitmap-dc (new bitmap-dc% (bitmap _bitmap)))
>                   (_width  (send _bitmap get-width))
>                   (_height (send _bitmap get-height))
>                   (_pixels (make-bytes (* 4 _width _height)))
>                   (_copy (make-object bitmap% _width _height #f)))
>              (send _bitmap-dc get-argb-pixels 0 0 _width _height _pixels 
> #f)
>              (send _bitmap-dc set-bitmap _copy)
>              (send _bitmap-dc set-argb-pixels 0 0 _width _height _pixels 
> #f)
>              (send _bitmap-dc set-bitmap #f) ; 'release' the bitmap
>              _copy)
> 
> - dr
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.