简体   繁体   English

如何使用R创建和保存1x1像素透明png?

[英]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? 我想在R中创建一个1x1像素的透明png文件。有没有办法这样做或者我必须“复制”预制的1x1像素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. 但这不会创建透明像素,而是1x1白色像素。

I need the 1x1 pixel .png file as a placeholder in case there are no data to be plotted. 我需要1x1像素.png文件作为占位符,以防没有要绘制的数据。

One way would be using png::writePNG : 一种方法是使用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. 这创建了一个透明的1x1像素(对于RGB和alpha中的每一个,将4个通道设置为零),我通过在GIMP中打开它来确认。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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