► |  | GUI: Racket Graphics Toolkit

1 | Overview
2 | Reference
3 | Configuration
4 | Dynamic Loading
| Bibliography
| Index

► | 2 | Reference

2.1 | Windowing Classes
2.2 | Windowing Functions
2.3 | Drawing Classes
2.4 | Drawing Functions
2.5 | Editor Classes
2.6 | Editor Functions
2.7 | WXME Decoding

▼ | 2.3 | Drawing Classes

2.3.1 | bitmap%
2.3.2 | bitmap-dc%
2.3.3 | brush%
2.3.4 | brush-list%
2.3.5 | color%
2.3.6 | color-database<%>
2.3.7 | dc<%>
2.3.8 | dc-path%
2.3.9 | font%
2.3.10 | font-list%
2.3.11 | font-name-directory<%>
2.3.12 | gl-config%
2.3.13 | gl-context<%>
2.3.14 | pen%
2.3.15 | pen-list%
2.3.16 | point%
2.3.17 | post-script-dc%
2.3.18 | printer-dc%
2.3.19 | ps-setup%
2.3.20 | region%

On this page:

draw-bitmap-section-smooth
get-argb-pixels
get-bitmap
get-pixel
set-argb-pixels
set-bitmap
set-pixel

Inherited methods:
from dc<%>
cache-font-metrics-key
clear
draw-arc
draw-bitmap
draw-bitmap-section
draw-ellipse
draw-line
draw-lines
draw-path
draw-point
draw-polygon
draw-rectangle
draw-rounded-rectangle
draw-spline
draw-text
end-doc
end-page
get-alpha
get-background
get-brush
get-char-height
get-char-width
get-clipping-region
get-font
get-gl-context
get-origin
get-pen
get-scale
get-size
get-smoothing
get-text-background
get-text-extent
get-text-foreground
get-text-mode
glyph-exists?
ok?
set-alpha
set-background
set-brush
set-clipping-rect
set-clipping-region
set-font
set-origin
set-pen
set-scale
set-smoothing
set-text-background
set-text-foreground
set-text-mode
start-doc
start-page
try-color

top ← prev up next →

bitmap-dc% : class?
superclass: object%

extends: | dc<%>

A bitmap-dc% object allows drawing directly into a bitmap. A bitmap% object must be supplied at initialization or installed into a bitmap DC using set-bitmap before any other method of the DC is called, except get-text-extent, get-char-height, or get-char-width. If any other bitmap-dc% method is called before a bitmap is selected, the method call is ignored.

Drawing to a bitmap-dc% with a color bitmap is guaranteed to produce the same result as drawing into a canvas% instance (with appropriate clipping and offsets). Thus, a bitmap-dc% can be used for offscreen staging of canvas content.

( new bitmap-dc% [bitmap bitmap]) → ( is-a?/c bitmap-dc% )
bitmap : ( or/c ( is-a?/c bitmap% ) false/c )

Creates a new memory DC. If bitmap is not #f, it is installed into the DC so that drawing commands on the DC draw to bitmap. Otherwise, no bitmap is installed into the DC and set-bitmap must be called before any other method of the DC is called.

( send a-bitmap-dc draw-bitmap-section-smooth |  | source |
|  | dest-x |
|  | dest-y |
|  | dest-width |
|  | dest-height |
|  | src-x |
|  | src-y |
|  | src-width |
|  | src-height |
|  | mask) |

→ boolean?
source : ( is-a?/c bitmap% )
dest-x : real?
dest-y : real?
dest-width : ( and/c real? ( not/c negative? ))
dest-height : ( and/c real? ( not/c negative? ))
src-x : real?
src-y : real?
src-width : ( and/c real? ( not/c negative? ))
src-height : ( and/c real? ( not/c negative? ))
mask : ( or/c ( is-a?/c bitmap% ) false/c )

Display part of a bitmap with smooth scaling. For most platforms, this method produces better results than adjusting the scale of a drawing context before using draw-bitmap and draw-bitmap-section, but this method is much slower.

( send a-bitmap-dc get-argb-pixels |  | x |  |  |  |
|  | y |  |  |  |
|  | width |  |  |  |
|  | height |  |  |  |
|  | pixels |  |  |  |
| [ | alpha?]) |  | → |  | void?

x : real?
y : real?
width : ( integer-in 1 10000)
height : ( integer-in 1 10000)
pixels : ( and/c bytes? ( not/c immutable? ))
alpha? : any/c = #f

Gets a rectangle of pixels in the bitmap, subject to the same rules and performance characteristics of get-pixel, except that the block get is likely to be faster than the sequence of individual gets. Also, the bitmap% class also provides the same method directly, so it is not necessary to select a bitmap into a DC to extracts its pixel values.

The pixel RGB values are copied into pixels. The first byte represents an alpha value of the pixel at (x, y), the second byte represents a red value of the pixel at (x, y), the third byte is the blue value, etc. In this way, the first width * height *4 bytes of pixels are set to reflect the current pixel values in the DC. The pixels are in row-major order, left to right then top to bottom.

If alpha? is false, then the alpha value for each pixel is set to 255. If alpha? is true, then only the alpha value is set for each pixel, based on each pixel’s inverted value. Thus, the same pixels byte string is in general filled from two bitmaps: one (the main image) for the pixel values and one (the mask) for the alpha values.

( send a-bitmap-dc get-bitmap )
→ ( or/c ( is-a?/c bitmap% ) false/c )

Gets the bitmap currently installed in the DC, or #f if no bitmap is installed. See set-bitmap for more information.

( send a-bitmap-dc get-pixel x y color) → boolean?
x : real?
y : real?
color : ( is-a?/c color% )

Fills color with the color of the current pixel at position (x, y) in the drawing context. If the color is successfully obtained, the return value is #t, otherwise the result is #f.

Under X, interleaving drawing commands with get-pixel calls (for the same bitmap-dc% object) incurs a substantial performance penalty, except for interleaved calls to set-pixel, set-argb-pixels, and get-argb-pixels.

( send a-bitmap-dc set-argb-pixels |  | x |  |  |  |
|  | y |  |  |  |
|  | width |  |  |  |
|  | height |  |  |  |
|  | pixels |  |  |  |
| [ | alpha?]) |  | → |  | void?

x : real?
y : real?
width : ( integer-in 1 10000)
height : ( integer-in 1 10000)
pixels : bytes?
alpha? : any/c = #f

Sets a rectangle of pixels in the bitmap, subject to the same rules and performance characteristics of set-pixel, except that the block set is likely to be faster than the sequence of individual sets.

The pixel RGB values are taken from pixels. The first byte represents an alpha value, the second byte represents a red value to used for the pixel at (x, y), the third byte is a blue value, etc. In this way, the first width * height * 4 bytes of pixels determine the new pixel values in the DC. The pixels are in row-major order, left to right then top to bottom.

If alpha? is false, then the alpha value for each pixel is ignored. If alpha? is true, then each pixel is set based only on the alpha value, but inverted to serve as a mask. Thus, the same pixels byte string is in general used with two bitmaps, one (the main image) for the pixel values and one (the mask) for the alpha values.

( send a-bitmap-dc set-bitmap bitmap) → void?
bitmap : ( or/c ( is-a?/c bitmap% ) false/c )

Installs a bitmap into the DC, so that drawing operations on the bitmap DC draw to the bitmap. A bitmap is removed from a DC by setting the bitmap to #f.

A bitmap can be selected into at most one bitmap DC, and only when it is not used by a control (as a label) or in a pen% or brush% (as a stipple). If the argument to set-bitmap is already in use by another DC, a control, a pen%, or a brush%, an exn:fail:contract exception is raised.

( send a-bitmap-dc set-pixel x y color) → void?
x : real?
y : real?
color : ( is-a?/c color% )

Sets a pixel in the bitmap.

The current clipping region might not affect the pixel change. Under X, interleaving drawing commands with set-pixel calls (for the same bitmap-dc% object) incurs a substantial performance penalty, except for interleaved calls to get-pixel, get-argb-pixels, and set-argb-pixels.
top ← prev up next →