fix and document failure handling of image reading in bitmap%

This commit is contained in:
Matthew Flatt 2010-11-07 06:50:52 -07:00
parent 7a2cee44cd
commit ba2ea79f12
3 changed files with 18 additions and 9 deletions

View File

@ -755,8 +755,10 @@
(make-object bitmap% w h #f alpha?))
(define/top (read-bitmap [path-string? filename]
[bitmap-file-kind-symbol? [kind 'unknown/alpha]])
(make-object bitmap% filename kind))
[bitmap-file-kind-symbol? [kind 'unknown/alpha]]
[(make-or-false color%) [bg-color #f]]
[any? [complain-on-failure? #t]])
(make-object bitmap% filename kind bg-color complain-on-failure?))
(define/top (make-monochrome-bitmap [exact-positive-integer? w]
[exact-positive-integer? h]

View File

@ -25,7 +25,8 @@ Sometimes, a bitmap object creation fails in a low-level manner. In
'xbm 'xbm/alpha 'xpm 'xpm/alpha
'bmp 'bmp/alpha)
'unknown]
[bg-color (or/c (is-a?/c color%) false/c) #f])
[bg-color (or/c (is-a?/c color%) false/c) #f]
[complain-on-failure? any/c #f])
([bits bytes?]
[width exact-positive-integer?]
[height exact-positive-integer?]))]{
@ -48,7 +49,6 @@ When @scheme[in] is provided: Creates a bitmap from a file format,
where @scheme[kind] specifies the format. See @method[bitmap%
load-file] for details.
When a @scheme[bits] byte string is provided: Creates a monochrome
bitmap from an array of bit values, where each byte in @scheme[bits]
specifies eight bits, and padding bits are added so that each bitmap
@ -156,7 +156,8 @@ Returns @scheme[#f] if the bitmap is monochrome, @scheme[#t] otherwise.
'xbm 'xbm/alpha 'xpm 'xpm/alpha
'bmp 'bmp/alpha)
'unknown]
[bg-color (or/c (is-a?/c color%) false/c) #f])
[bg-color (or/c (is-a?/c color%) false/c) #f]
[complain-on-failure? any/c #f])
boolean?]{
Loads a bitmap from a file format that read from @racket[in], unless
@ -165,7 +166,9 @@ Loads a bitmap from a file format that read from @racket[in], unless
If the bitmap is in use by a
@scheme[bitmap-dc%] object or a control, the image data is not
loaded. The bitmap changes its size and depth to match that of
the loaded image.
the loaded image. If an error is encountered when reading the file format,
an exception is raised only if @racket[complain-on-failure?] is true (which is
@emph{not} the default).
The @scheme[kind] argument specifies the file's format:

View File

@ -60,11 +60,15 @@ overloaded.}
'png 'png/mask 'png/alpha
'xbm 'xbm/alpha 'xpm 'xpm/alpha
'bmp 'bmp/alpha)
'unknown/alpha])
'unknown/alpha]
[bg-color (or/c (is-a?/c color%) false/c) #f]
[complain-on-failure? any/c #t])
(is-a?/c bitmap%)]{
Returns @racket[(make-object bitmap% in kind)], but this procedure is
preferred because it defaults @racket[kind] in a more useful way.}
Returns @racket[(make-object bitmap% in kind bg-color
complain-on-failure?)], but this procedure is preferred because it
defaults @racket[kind] and @racket[complain-on-failure?] in a more
useful way.}
@defthing[the-brush-list (is-a?/c brush-list%)]{