[racket] Problem loading a bitmap% to use for a cursor%

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Oct 18 12:09:25 EDT 2012

Although your attached bitmap is in 1-bit format, it has a color
palette in the PNG file format, as opposed to being identified as
"grayscale" at that level.

I couldn't figure out how to get Preview or GIMP to re-save the PNG as
grayscale. Meanwhile, there we bugs in `racket/draw' for monochrome PNG
reading and writing; I'll soon push repairs.

After the repairs,

 (define bm (make-object bitmap% 16 16 #t #f))
 (define bm2 (read-bitmap "test-icon.png"))
 (send (send bm make-dc) draw-bitmap bm2 0 0)
 (send bm save-file "t2.png" 'png)

converts "test-icon.png" to a grayscale monochrome "t2.png", and that
file works for a cursor.

At Thu, 11 Oct 2012 15:18:13 -0600, Kieron Hardy wrote:
> Hi all,
> I'm having trouble loading a 16x16 monochrome image such that it can be
> used as a cursor%.
> The documentation states that using load-file with a kind of 'bmp always
> loads as colour, but it would be nice to have a new kind (perhaps
> 'monochrome-bmp) that loads monochrome images to monochrome bitmaps.
> The documentation also states that a monochrome png will load as a
> monochrome bitmap%, but it seems to always load as colour (changing the bit
> depth from 1 to 32 during the load-file, regardless of the value specified
> for kind). Perhaps there's something wrong with my image file (attached)
> but gimp and Windows both show a 1-bit colour depth.
> I have a work-around, in that converting the image to xbm seems to work.
> But I'm still interested to know what I was doing wrong, anyone have any
> ideas?
> Cheers,
> Kieron.
> ****
> #lang racket
> (require racket/gui)
> (define bm (make-object bitmap% 16 16 #t #f))
> (printf "  ~a ~a ~a ~a~n" (send bm get-width) (send bm get-height) (send bm
> get-depth) (send bm is-color?))
> (send bm load-file "test-icon.png" 'png #f #t)
> ;(send bm load-file "test-icon.xbm" 'xbm #f #t)
> (printf "  ~a ~a ~a ~a~n" (send bm get-width) (send bm get-height) (send bm
> get-depth) (send bm is-color?))
> (define cursor (make-object cursor% bm bm 0 0))

Posted on the users mailing list.