从Music21保存图像文件

时间:2018-12-06 05:27:49

标签: python music21 music-notation

我已经下载了一堆.krn文件,我想使用music21将它们转换为图像-png或jpgs。我已经尝试过了:

当我这样做时:

from music21 import *   
op = krnfile
s = converter.parse(op)
s.show()

我在使用的Jupyter Notebook中看到了一个很棒的图像文件,但是当我尝试以编程方式保存该文件时,如下所示:

s.write(fp = 'outputfile.png', fmt = 'png')

它说:

Music21ObjectException: cannot support showing in this format yet: png

这似乎有些奇怪,因为它显然设法制作了要在笔记本中显示的图像。

似乎我可以使用this中的LilypondConverter.createPNG(fileName=None),但是是否需要安装Lilypond?我已经安装了MuseScore2,在我致电s.show()时会打开。

非常感谢! 亚历克斯

1 个答案:

答案 0 :(得分:0)

如果使用n.show('lily.png'),它将在某处创建一个临时png文件。尝试使用它,图像可能会打开。

对不起,我还不了解,希望对您有所帮助。