球拍博士中的位图 [英] bitmap in dr racket
本文介绍了球拍博士中的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 dr 球拍中的帧 (gui) 上加载位图???请给出必要的代码和参考资料....
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 建议:您可以使用带有位图的 `message%' 作为它的标签.这当然少了很多代码.这取决于你打算去哪里.
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)
这篇关于球拍博士中的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文