From f4b4e00c5585dd73b14454820ee99c521b6ad83a Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 29 Dec 2011 22:18:07 -0600 Subject: [PATCH] added bitmap/file closes PR 12466 --- collects/2htdp/image.rkt | 3 ++- collects/2htdp/private/image-more.rkt | 9 +++++++++ collects/teachpack/2htdp/scribblings/image.scrbl | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/collects/2htdp/image.rkt b/collects/2htdp/image.rkt index d1de83cc4f..9da902d586 100644 --- a/collects/2htdp/image.rkt +++ b/collects/2htdp/image.rkt @@ -135,7 +135,8 @@ and they all have good sample contracts. (It is amazing what we can do with kids save-svg-image freeze - bitmap/url) + bitmap/url + bitmap/file) (provide bitmap empty-image) diff --git a/collects/2htdp/private/image-more.rkt b/collects/2htdp/private/image-more.rkt index 91a2e05477..3941f60585 100644 --- a/collects/2htdp/private/image-more.rkt +++ b/collects/2htdp/private/image-more.rkt @@ -1317,6 +1317,14 @@ (λ (port) (make-object bitmap% port 'unknown #f #t))))) +(define/chk (bitmap/file filename) + (unless (file-exists? filename) + (error 'bitmap/file + "could not find the file ~a" + filename)) + (rotate + 0 + (read-bitmap filename))) (define/chk (image->color-list image) (let* ([w (image-width image)] @@ -1495,6 +1503,7 @@ bitmap bitmap/url + bitmap/file swizzle diff --git a/collects/teachpack/2htdp/scribblings/image.scrbl b/collects/teachpack/2htdp/scribblings/image.scrbl index 95ca2a8f4f..00d520eee2 100644 --- a/collects/teachpack/2htdp/scribblings/image.scrbl +++ b/collects/teachpack/2htdp/scribblings/image.scrbl @@ -1247,6 +1247,16 @@ See also the @racketmodname[2htdp/planetcute] library. and then paste it into your program or download it and use @racket[bitmap]. } +@defproc[(bitmap/file [ps path-string?]) image?]{ + Loads the image from @racket[ps]. + + If @racket[ps] is a relative path, the file is relative to + the current directory. (When running in DrRacket, the current + directory is set to the place where the definitions window is + saved, but in general this can be an arbitrary directory.) +} + + @defproc[(image->color-list [image image?]) (listof color?)]{ Returns a list of colors that correspond to the colors in the image, reading from left to right, top to bottom.