When using grid.raster() or rasterImage to render a PNG image through Cairo device, interpolate must be set to FALSE. Otherwise, no graphics is rendered.
-- render png image with interpolate = TRUE to a png file plot_cairo.png
R> Cairo(file = "plot_cairo.png")
R> grid.raster(readPNG("Rplot001.png"), interpolate=TRUE)
R> dev.off()
-- render png image with interpolate = FALSE to a png file plot_cairo_no_interp.png
R> Cairo(file = "plot_cairo_no_interp.png")
R> grid.raster(readPNG("Rplot001.png"), interpolate=FALSE)
R> dev.off()
R> grid.raster(readPNG("plot_cairo.png")) # no graphic on the plot
R> grid.raster(readPNG("plot_cairo_no_interp.png")) # graphic is rendered on the plot
Other graphics devices, e.g., X11, png, work with no issue on interpolate argument setting.
When using grid.raster() or rasterImage to render a PNG image through Cairo device, interpolate must be set to FALSE. Otherwise, no graphics is rendered.
-- create an png file R> png() R> plot(1:10) R> dev.off() R> grid.raster(readPNG("Rplot001.png"))
-- render png image with interpolate = TRUE to a png file plot_cairo.png R> Cairo(file = "plot_cairo.png") R> grid.raster(readPNG("Rplot001.png"), interpolate=TRUE) R> dev.off()
-- render png image with interpolate = FALSE to a png file plot_cairo_no_interp.png R> Cairo(file = "plot_cairo_no_interp.png") R> grid.raster(readPNG("Rplot001.png"), interpolate=FALSE) R> dev.off()
R> grid.raster(readPNG("plot_cairo.png")) # no graphic on the plot R> grid.raster(readPNG("plot_cairo_no_interp.png")) # graphic is rendered on the plot
Other graphics devices, e.g., X11, png, work with no issue on interpolate argument setting.