if (FALSE) {
## first: Let's make a raster out of the 'volcano' data, which we can use in the example:
volcano.raster <- as.raster(t(matrix(terrain.colors(1 + diff(range(volcano)))[volcano -
min(volcano) + 1], nrow(volcano))))
## convert the raster into binary (logical) bitmap data:
volcano.bm <- rasterToBitmap(volcano.raster)
## The palette for the indexed colours of the generated bitmap is returned as
## attribute. There is no transparency is the image:
attributes(volcano.bm)
## We can also include a custom function for colour quantisation. Let's include
## some dithering:
volcano.dither <- rasterToBitmap(volcano.raster,
indexing = function(x, length.out) {
index.colours(x, length.out,
dither = "floyd-steinberg")
})
## You can also use a custom indexing function to force a specified palette,
## in this case black and white:
volcano.bw <- rasterToBitmap(volcano.raster,
indexing = function(x, length.out) {
index.colours(x, length.out,
palette = c("black", "white"),
dither = "floyd-steinberg")
})
## Make a bitmap using a special display mode (HAM6):
volcano.HAM <- rasterToBitmap(volcano.raster, "HAM6")
}
Run the code above in your browser using DataLab