开发者

bitmap in dr racket [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 5 years ago.

Improve this question

how to load a bitmap on a frame (gui) in dr racket??? please give the necessary code 开发者_运维知识库and references....


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜