#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)
I admit, I'm having a hard time finding the right spot in the docs to point you to. Here's some code that does it, but I have a sneaking suspicion that there's a much easier way to get this done:
#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)
update: Matthew Flatt suggests: You could use `message%' with the bitmap as its label. This is certainly lots less code. It depends on where you're going with this.
#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)
发布评论
评论(1)
我承认,我很难在文档中找到正确的位置来指向您。这是一些执行此操作的代码,但我隐隐怀疑有一种更简单的方法可以完成此操作:
更新:Matthew Flatt 建议:您可以使用“message%”并将位图作为其标签。这肯定少了很多代码。这取决于你要做什么。
I admit, I'm having a hard time finding the right spot in the docs to point you to. Here's some code that does it, but I have a sneaking suspicion that there's a much easier way to get this done:
update: Matthew Flatt suggests: You could use `message%' with the bitmap as its label. This is certainly lots less code. It depends on where you're going with this.