我有以下代码来创建pdf文件:
#lang racket/gui
(define dc
(new pdf-dc%
[interactive #f]
[use-paper-bbox #f]
[width 500]
[height 800]
[output "testfile.pdf"]))
(send dc start-doc "file output")
(send dc start-page)
(send dc draw-text "Test Text" 100 100)
(send dc draw-line 100 100 200 200)
(send dc end-page)
(send dc end-doc)
我可以在此页面上绘制椭圆,矩形等:https://docs.racket-lang.org/draw/dc___.html
然而,我找不到如何将图像(jpg / png / bmp)放在这里。我试过了:
(send dc draw-bitmap "mypict.jpg" 200 200) ;; NOT WORKING;
但它不起作用。错误是:
draw-bitmap: contract violation
expected: (is-a?/c bitmap%)
given: "mypict.jpg"
in: the 1st argument of
(->*m
((is-a?/c bitmap%) real? real?)
((or/c 'solid 'opaque 'xor)
(is-a?/c color%)
(or/c (is-a?/c bitmap%) #f))
boolean?)
contract from: (class pdf-dc%)
以下语句运行时没有任何错误,但如何在其中插入文件名?
(send dc draw-bitmap (make-object bitmap% 100 100) 200 200)
答案 0 :(得分:2)
问题是"mypict.jpg"
是一个字符串,而不是bitmap%
。
(make-object bitmap% "mypict.jpg")
将为您创建一个合适的位图对象。