Bitmap uses low-level data pointers to reduce overhead in working with CGImage
.
It allows you to get and set pixels directly through a 2-argument subscript, as well as offering various bulk creation/modification operations.
Identify pixels that are neither fully opaque nor fully transparent and turn them red, clearing the rest.
for y in 0..<bitmap.height {
for x in 0..<bitmap.width {
if case 1...254 = bitmap[x, y].alpha {
bitmap[x, y] = .red
} else {
bitmap[x, y] = .clear
}
}
}
turns this | into this |
For more examples, please take a look at the unit tests. All non-trivial public endpoints have documentation attached too, so it shouldn't be too hard to figure out how everything works if you just play around a little.