[plt-scheme] How to crop images?

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed May 14 21:30:33 EDT 2008

One way would be to make a mask bitmap and use that mask with the bitmap.

Another way to make a clipping region and set it on the dc before you
call draw-bitmap.

Here's how to set the clipping region (this is v4 code -- I think it
will run in 372 without the #lang line, tho)

#lang scheme/gui

(define bm (make-object bitmap% (build-path (collection-path "icons")

(define (draw dc)
  (let ([old-clip (send dc get-clipping-region)]
        [new-clip (new region% [dc dc])])
    (send new-clip set-rounded-rectangle 80 80 100 100)
    (send dc set-clipping-region new-clip)
    (send dc draw-bitmap bm 0 0)
    (send dc set-clipping-region old-clip)))

(define f (new frame% [label ""]))
(define c (new canvas%
               [parent f]
               [paint-callback (λ (c dc) (draw dc))]
               [min-width (send bm get-width)]
               [min-height (send bm get-height)]))
(send f show #t)


On Wed, May 14, 2008 at 8:19 PM, zen1986 at gmail.com <zen1986 at gmail.com> wrote:
> Hi everyone,
> I am doing a board game and want to put arbitrary background to
> arbitrary tile shapes.
> I have tried using bitmap. but it seems it can only create a
> rectangular background, while I want arbitrary shape, say triangle,
> hexagon..
> So I wonder if I can get any help here.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.