Learn R Programming

png (version 0.1-0)

writePNG: Write a bitmap image in PNG format

Description

Create a PNG image from an array or matrix.

Usage

writePNG(image, target)

Arguments

image
image represented by a real matrix or array with values in the range of 0 to 1. Values outside this range will be clipped. The object must be either two-dimensional (grayscale matrix) or three dimensional array (third dimension specifying the plan
target
Either name of the file to write to or a raw vector (raw() is good enough) indicating that the output should be a raw vector.

Value

  • Either NULL if the target is a file or a raw vector containing the compressed PNG image if the target was a raw vector.

See Also

link{readPNG}

Examples

Run this code
# read a sample file (R logo)
img <- readPNG(system.file("img","Rlogo.png",package="png"))
# write the image into a raw vector
r <- writePNG(img, raw())
# read it back again
img2 <- readPNG(r)
# it better be the same
identical(img, img2)

Run the code above in your browser using DataLab