[racket] monochrome bitmaps

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Nov 1 10:21:52 EDT 2012

At Wed, 31 Oct 2012 23:06:39 -0400, Harry Spier wrote:
> Dear list members,
> 
> I see from the Racket Drawing Toolkit documentation that there are
> monochrome bitmaps but I'm not clear from the documentation how to
> access and manipulate these monochrome bitmaps.
> 
> Specifically:
> 1) If I load a bitmap with a greyscale image file using the form:
>        (make-object bitmap%	 	
>             in ;path to monochrome image files 	 	 	
>  	 [ kind	 	 	 	
>  	   bg-color	 	 	 	
>  	 complain-on-failure?])	
> 
> Will that create a monochrome bitmap from  the greyscale image? 

Yes, if the file format is PNG or XBM, but other file formats always
load into color bitmaps.

> If
> not is there another way to load a file as a monochrome bitmap?

After loading any kind of bitmap, you can create a same-sized
monochrome bitmap and then draw a color bitmap into the monochrome one
using `draw-bitmap' (after creating a `bitmap-dc%' to draw into the
monochrome bitmap).

> 2) How do I access pixel intensities from a monochrome bitmap?
> The documentation for get-argb-pixels says it copies rgb values plus
> alpha channel into pixels.  For a monochrome bitmap is it the alpha
> channel which holds the pixel intensity where 1 is black and 0 is
> white?

The same pixel intensities are used as for color bitmaps: white is
255,255,255 and black is 0,0,0.

A monocrhome bitmap doesn't have an alpha channel, but it you ask for
its pixels in `just-alpha?' mode, then while pixels generate a 0 alpha
and black pixels generate a 255 alpha.


Posted on the users mailing list.