drracket 中的位图

发布于 2024-10-23 19:03:28 字数 1435 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初熏 2024-10-30 19:03:28

我承认,我很难在文档中找到正确的位置来指向您。这是一些执行此操作的代码,但我隐隐怀疑有一种更简单的方法可以完成此操作:

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

更新:Matthew Flatt 建议:您可以使用“message%”并将位图作为其标签。这肯定少了很多代码。这取决于你要做什么。

#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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文