2011-03-18 54 views

回答

3

我承認,我很難在文檔中找到正確的位置來指向您。下面是一些代碼,這樣做,但我有一個偷渡懷疑,有一個更簡單的方法來完成這件事:

#lang racket 

(require racket/draw 
     mred) 

;; define a canvas that displays a bitmap when its on-paint 
;; method is called 
(define bitmap-canvas% 
    (class canvas% 
    (init-field [bitmap #f]) 
    (inherit get-dc) 
    (define/override (on-paint) 
     (send (get-dc) draw-bitmap bitmap 0 0)) 
    (super-new))) 

;; load the bitmap 
(define bitmap (read-bitmap "/tmp/red-arrow.bmp")) 

;; create a new frame (top-level window) 
(define f (new frame% [label "foo"] [width 100] [height 100])) 

;; create a canvas 
(define the-canvas (new bitmap-canvas% [parent f] [bitmap bitmap])) 

;; show the canvas 
(send f show #t) 

更新:馬修·弗拉特提示:你可以使用`消息%」與位圖它的標籤。這當然是很少的代碼。這取決於你要去哪裏。

#lang racket/gui 

(define bitmap (read-bitmap "/tmp/red-arrow.bmp")) 

(define f (new frame% [label "Bitmap"])) 
(new message% [parent f] [label bitmap]) 
(send f show #t)