简体   繁体   中英

How to create and save a 1x1 pixel transparent png using R?

I would like to create a 1x1 pixel transparent png file in R. Is there any way to do so or do i have to "copy" a premade 1x1 pixel png?

I've tryed

empty_frame = imfill(x = 1, y = 1, z = 1, val = "transparent", dim = NULL)

but this does not create a transparent pixel but a 1x1 white pixel.

I need the 1x1 pixel .png file as a placeholder in case there are no data to be plotted.

One way would be using png::writePNG :

png::writePNG(array(0, dim = c(1,1,4)), "pixel.png")

This creates a transparent 1x1 pixel (with 4 channels set at zero, for each of RGB and alpha), which I confirmed by opening it up in GIMP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM