如何将其变成pict中的像素的字节字符串?
(我的意思是,您会从呈现pict中获得的位图中的像素字节字符串)
此功能有效:
#lang racket/base
(require pict racket/class)
(define (pict->pixels p)
(define b (pict->bitmap p))
(define w (send b get-width))
(define h (send b get-height))
(define pixbuf (make-bytes (* 4 (inexact->exact (ceiling (* w h))))))
(send b get-argb-pixels 0 0 w h pixbuf)
pixbuf)
但是有更简单的方法吗?
是!有一个简单的方法:pict->argb-pixels
这是一个测试案例:
#lang racket/base
(require pict racket/class rackunit)
(define (pict->pixels p)
(define b (pict->bitmap p))
(define w (send b get-width))
(define h (send b get-height))
(define pixbuf (make-bytes (* 4 (inexact->exact (ceiling (* w h))))))
(send b get-argb-pixels 0 0 w h pixbuf)
pixbuf)
(define my-pict (jack-o-lantern 100))
(check-equal? (pict->pixels my-pict) (pict->argb-pixels my-pict))