如何使用Racket在web应用程序中绘制图片?
我正在寻找一种在我的简单web应用程序中绘制图片的方法。基本上,我正在尝试使用标准幻灯片库提交一张circle的图片,但它不起作用,我也不知道为什么 以下是一个示例:如何使用Racket在web应用程序中绘制图片?,web,racket,Web,Racket,我正在寻找一种在我的简单web应用程序中绘制图片的方法。基本上,我正在尝试使用标准幻灯片库提交一张circle的图片,但它不起作用,我也不知道为什么 以下是一个示例: #lang web-server/insta (require slideshow) (define (start request) (response/xexpr '(html (body (circle 10)) ) ) ) 您能
#lang web-server/insta
(require slideshow)
(define (start request)
(response/xexpr '(html
(body (circle 10))
)
)
)
您能告诉我如何在HTML页面上使用标准UTIL绘制图片吗?您需要为图像生成HTML IMG标记并提供正确的内容。一种方法是将图像源直接作为源放在网页中: 另一种方法是将图像源设置为url,将图像作为其响应发送:
#lang web-server/insta
(require pict
file/convertible)
;; pict-response : Pict -> Response
(define (pict-response pict)
(response/full 200 #"Ok"
(current-seconds) #"image/png"
(list)
(list (convert pict 'png-bytes))))
;; start : Request -> Response
(define (start request)
(send/suspend/dispatch
(lambda (make-url)
(response/xexpr
`(html
(body
(p "hello, here's a circle:")
(img ([src ,(make-url
(lambda (req)
(pict-response (circle 10))))]))))))))
谢谢你的回答,但我能用多参数程序画图吗?在这种情况下(圆圈20“实心”“蓝色”)@Dimitry,
pict
库中的circle
函数与2htdp/image
中的函数不同。使用pict
库的纯蓝色圆圈的代码为(彩色(磁盘20)“蓝色”)
。或者您可以将pict
的require行替换为2hdp/image
,因为该库的图像也可以转换为PNG字节。您甚至可以同时使用这两个库,因为pict
库函数通常可以接受2htdp/image
图像作为参数(但据我所知,不是相反)。您需要在中使用类似于前缀的内容来处理名称冲突。谢谢您的解释。我已经修好了,效果很好
#lang web-server/insta
(require pict
file/convertible)
;; pict-response : Pict -> Response
(define (pict-response pict)
(response/full 200 #"Ok"
(current-seconds) #"image/png"
(list)
(list (convert pict 'png-bytes))))
;; start : Request -> Response
(define (start request)
(send/suspend/dispatch
(lambda (make-url)
(response/xexpr
`(html
(body
(p "hello, here's a circle:")
(img ([src ,(make-url
(lambda (req)
(pict-response (circle 10))))]))))))))