Home

MaskBlt

MaskBlt is a Windows GDI function that performs a masked bit-block transfer from a source device context (DC) to a destination DC. It copies a specified rectangle of pixels from the source to the destination, but only at positions where a provided 1-bit-per-pixel mask bitmap has a set bit. The operation is controlled by a raster operation (ROP) code, which determines how the source and destination pixels are combined on the masked areas.

The function's signature is: MaskBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, hbmMask, xMask, yMask, dwRop).

Common uses of MaskBlt include sprite rendering and image compositing where certain pixels should be preserved

Notes and considerations include ensuring the mask dimensions align with the transfer area and understanding that

The
mask
bitmap
is
monochrome
(1bpp)
and
dictates
which
destination
pixels
are
affected.
The
xMask
and
yMask
parameters
specify
the
offset
into
the
mask,
allowing
the
same
mask
to
be
reused
for
different
destination
regions.
(masked
off)
while
others
are
updated.
It
is
often
employed
to
render
images
with
transparency
masks,
where
the
mask
defines
visible
versus
transparent
areas,
combined
with
a
desired
raster
operation.
MaskBlt
relies
on
the
GDI
raster
operations.
While
MaskBlt
remains
part
of
the
GDI
toolkit,
modern
applications
increasingly
use
alpha
blending
and
Direct2D
for
more
flexible
transparency
handling.
Related
functions
include
BitBlt,
TransparentBlt,
and
StretchBlt.