bitmap in dr racket [closed]

蹲街弑〆低调 提交于 2019-12-02 12:06:09

问题


how to load a bitmap on a frame (gui) in dr racket??? please give the necessary code and references....


回答1:


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)


来源:https://stackoverflow.com/questions/5355251/bitmap-in-dr-racket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!