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.
constructor
(new bitmap-dc% [bitmap bitmap]) → (is-a?/c bitmap-dc%)
bitmap : (or/c (is-a?/c bitmap%) #f)
method
(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 [ style color 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?)) style : (or/c 'solid 'opaque 'xor) = 'solid
color : (is-a?/c color%) = (send the-color-database find-color "black") mask : (or/c (is-a?/c bitmap%) #f) = #f
method
(send a-bitmap-dc get-argb-pixels x y width height pixels [ just-alpha? pre-multiplied?]) → void? x : exact-nonnegative-integer? y : exact-nonnegative-integer? width : exact-nonnegative-integer? height : exact-nonnegative-integer? pixels : (and/c bytes? (not/c immutable?)) just-alpha? : any/c = #f pre-multiplied? : any/c = #f
The pixel RGB values and alphas are copied into pixels (or just alpha values if just-alpha? is true). 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 green 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 the bitmap has an alpha channel, then the alpha value for each pixel is always set in pixels. If just-alpha? is false and the bitmap does not have an alpha channel, then the alpha value for each pixel is set to 255. If just-alpha? is true, then only the alpha value is set for each pixel; if the bitmap has no alpha channel, then the alpha value is based on each pixel’s inverted RGB average. Thus, when a bitmap has a separate mask bitmap, 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.
If pre-multiplied? is true, just-alpha? is false, and the bitmap has an alpha channel, then RGB values in the result are scaled by the corresponding alpha value (i.e., multiplied by the alpha value and then divided by 255).
If the bitmap has a backing scale other than 1.0, the result of get-argb-pixels is as if the bitmap is drawn to a bitmap with a backing scale of 1.0 and the pixels of the target bitmap are returned.
method
(send a-bitmap-dc get-bitmap) → (or/c (is-a?/c bitmap%) #f)
method
x : exact-nonnegative-integer? y : exact-nonnegative-integer? color : (is-a?/c color%)
method
(send a-bitmap-dc set-argb-pixels x y width height pixels [ just-alpha? pre-multiplied?]) → void? x : real? y : real? width : exact-nonnegative-integer? height : exact-nonnegative-integer? pixels : bytes? just-alpha? : any/c = #f pre-multiplied? : any/c = #f
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 just-alpha? is false, then the alpha value for each pixel is used only if the DC’s current bitmap has an alpha channel. If just-alpha? is true and the bitmap has an alpha channel, then the bitmap is not modified. If just-alpha? is true and the bitmap has no alpha channel, then each pixel is set based only on the alpha value, but inverted to serve as a mask. Thus, when working with bitmaps that have an associated mask bitmap instead of an alpha channel, the same pixels byte string is used with two bitmaps: one (the main image) for the pixel values and one (the mask) for the alpha values.
If pre-multiplied? is true, just-alpha? is false, and the bitmap has an alpha channel, then RGB values in pixels are interpreted as scaled by the corresponding alpha value (i.e., multiplied by the alpha value and then divided by 255). If an R, G, or B value is greater than its corresponding alpha value (which is not possible if the value is properly scaled), then it is effectively reduced to the alpha value.
If the bitmap has a backing scale other than 1.0, then pixels are effectively scaled by the backing scale to obtain pixel values that are installed into the bitmap.
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.