次のコードを使用して、キャンバス上に画像のリストを表示しようとしています。ただし、空のフレームが表示され、 'for'ループ全体が実行されて最終的なエフェクトがフレームに表示されるまで画像は表示されません。キャンバス上の画像のリストをアニメ化する
#lang racket/gui
(require 2htdp/image)
(define frame (new frame%
[label "Example"]
[width 500]
[height 500]))
(send frame show #t)
; (sleep 1) ; tried this to allow time for frame to show properly; does not help;
(new canvas% [parent frame]
[paint-callback
(lambda (canvas dc)
(for ((i imglist)) ; imglist is a list of images to be displayed @ 1/second.
(send dc clear)
(send dc draw-bitmap
(image->bitmap i)
20 20)
; (send dc flush) ; this statement also does not help;
(sleep 1) ; to show animation effect from list of images;
))])
イメージ - >ビットマップ機能はからです:;から:https://lists.racket-lang.org/users/archive/2014-December/065110.html
(define (image->bitmap image)
(let* ([width (image-width image)]
[height (image-height image)]
[bm (make-bitmap width height)]
[dc (send bm make-dc)])
(send dc clear)
(send image draw dc 0 0 0 0 width height 0 0 #f)
bm))
はどこに問題があるとどのようにそれを解決することができますか?
はい、非常にうまく動作します。私は、DCオブジェクトを取得して無限ループで描画ビットマップを作成するために "(canvas get-dcを送信する")こともできますが、フレームクローズボタンが機能せず、プロセスがSTOPpedされなければなりませんDrRacket IDE。スレッドを使用するソリューションにはこのような問題はありません。 – rnso
私はそれを明確に示すための答えとしてこれを追加しました。 – rnso