Working with Images
Check which version of DrScheme you have. You can find the version
number in the interactions window after you press execute.
Setting up Images under DrScheme 206
The image operators are built-in to version 206. You do not need
to install anything in this case. The available operators are listed
below.
Setting up Images under DrScheme 205
Download the images distribution
to your computer.
Install the three .plt files in the distribution by selecting
"install .plt file" under the File menu in DrScheme and selecting each
file in turn.
Under the Language menu, choose "Add Teachpack" and select the
images-teachpack.ss file from the distribution. (Do not use
DrScheme's Open menu item for
images-teachpack.ss.)
The teachpack adds the operations listed in the next section.
Image Operations
- image=? contract is
image image -> bool
- Takes two images
and returns true if the images are the same, false
otherwise.
- image-width contract is
image -> num
- Takes an image and
returns its width in pixels.
- image-height contract is
image -> num
- Takes an image and
returns its height in pixels.
- image+ contract is
image image -> image
- Takes two images
image and produces an image where the second is placed on the
first. The top-left of the result image corresponds to the top-left of
the given images.
- offset-image+ contract is
image num num image -> image
- Like
image+, but with two number arguments inserted between the
image arguments. The first number is the number of pixels right to
shift the second image, and the secnd number is the number of pixels
down to shift the second image.
- offset-masked-image+ contract is
image num num image image ->
image
- Like offset-image+, but with an extra
image argument inserted before the last argument. This image must be
the same size as the last image, and pixels are copied from the last
image to the result only where the extra image has non-white
pixels.
- solid-box contract is
num num symbol ->
image
- Takes two numbers and a symbol
and produces an image. The first number determines the width of the
result image and the second number determines the height. The symbol
determines the color that fills the entire result image. See also the
list of available
colors.
- outline-box contract
is num num symbol ->
image
- Like solid-box, except
that only the border of the image uses the specified color, and the
rest of the image is
white.
- solid-dot contract is
num num symbol ->
image
- Like solid-box, except
that only a circle bounded by the image is filled with the specified
color, and the corners of the image are
white.
- outline-dot contract is
num num symbol ->
image
- Like solid-dot, except
that only the circle edge bounded by the image is draw with the
specified color, and the rest of the image is white.
- image-inside? : image image ->
bool
- Returns true if the second image appears somewhere
in the first, false otherwise.
- find-image : image image -> posn
- Returns a
posn reprsentating the location of the second image within the
first. (If the second image does not appear in the first, an error is
reported.) The result posn indicates the location of the second
image's top-left corner relative to the first image's top left
corner. The X part of the posn indicates the number of pixels to the
right that the second image's corner is shifted, and the Y part
indicates the number of pixels down that the second image's corner is
shifted.
- (define-struct color (red green blue))
- Colors
on a computer screen are represented by a combination of red, green,
and blue light intensities. The intensity of each color varies between
0 and 255. For example, pure blue is (make-color 0 0 255),
while (make-color 0 0 128) is a dim blue. Using the same
intensity for red, blue, and green always produces a shade of gray; in
particular, (make-color 0 0 0) is black, (make-color 255
255 255) is white, and (make-color 128 128 128) is a
medium gray. Other combinations produce other colors. For example,
(make-color 255 255 0) is bright yellow.
- image->color-list : image ->
list-of-color
- Returns a list of color values representing
the pixels of a given image. The first color corresponds to the
top-left pixel, the second color corresponds to the pixel one step to
the right, and so on --- left-to-right then top-to-bottom. The number
of colors is in the list is the same as the image's width times its
height.
- color-list->image : list-of-color num num ->
image
- The opposite of image->color-list. This
function needs the width and height of the image to construct, in
addition to the pixel content.
2135 Home Page