使用readPNG读取Magick创建的已编辑png文件时出现错误

问题描述 投票:0回答:1

我正在尝试使用readPNG读取使用程序包后创建的文件。这是我使用Magick软件包从两个图像中合并的png文件。我需要使用readPNG将其读取为栅格文件,以便以后可以使用annotate_custom将其插入到地图中。但我收到一条错误消息,说:

文件不是PNG格式

A <- image_read("Alogo.jpg")
image_trim(A)
A_twick<-image_resize(A, "130x130")
print(A_twick)

B <- image_read("Blogo.jpg")
image_trim(B)

combined<-image_append(c(B,A))
print(combined)
image_write(combined, "combinedlogo.png")

logo <- readPNG("logo/combinedlogo.png")
# here is the error message "Error in readPNG("logo/combinedlogo.png") : file is not in PNG format"

RI2<-RI+ annotation_custom(combined, xmin=-71.92, xmax=-71.82, ymin=41.15, ymax=41.23)

我错过了什么吗?还是有什么办法可以实现我的目标?预先谢谢!

r png rmagick
1个回答
0
投票

[您假设Magick知道您想将文件另存为png,因为您使用的是“ .png”文件扩展名,但实际上需要指定它:

magick::image_write(combined, "combinedlogo.png", format = "PNG")
logo <- png::readPNG("logo/combinedlogo.png")

您现在应该可以将其作为3维数组访问logo

不幸的是,如果没有原始文件,我将无法复制此文件。

© www.soinside.com 2019 - 2024. All rights reserved.