在 Windows 10 上保存为 BMP 文件

发布于 2025-01-12 21:56:22 字数 329 浏览 1 评论 0原文

我正在尝试将绘图保存到 Windows 10 上的 bmp 文件中。我可以使用交互式终端来完成此操作:windows 或使用 GUI 的 qt。但我不知道如何用命令来做到这一点。这样做只会产生一个空文件。

gnuplot> set terminal windows

Terminal type is now 'windows'
Options are '0 color solid butt enhanced standalone'
gnuplot> set output "file.bmp"  
gnuplot> plot sin(x)
Closing file.bmp

I'm trying to save a plot to a bmp file on Windows 10. I can do it with the interactive terminals: windows or qt using the GUI. But I can't figure out how to do it with commands. Doing this just results in an empty file.

gnuplot> set terminal windows

Terminal type is now 'windows'
Options are '0 color solid butt enhanced standalone'
gnuplot> set output "file.bmp"  
gnuplot> plot sin(x)
Closing file.bmp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独﹏钓一江月 2025-01-19 21:56:22

如果我启动 gnuplot 控制台并 set term windows 并输入 plot sin(x) gnuplot 就会崩溃。这肯定是我的系统(Win10,gnuplot 5.4.1)的一个错误或问题。如果我将终端选项设置为停靠布局1,1,我只能在不崩溃的情况下进行绘图。但是,我得到了一个像你一样的空 BMP 文件。

实际上,到目前为止,我还没有找到任何从 4.4.0 开始的 gnuplot 版本,它似乎能够创建正确的 BMP 输出。

因此,我的建议是创建一个 PNG 输出并将其转换为 BMP,例如通过 ImageMagick。

  • 下载并解压 ImageMagick

    的 .zip 版本

  • 仅复制文件 magick.exe 到你的 gnuplot 工作目录(或者你的系统可以找到它的其他地方)

  • 将下面的脚本保存到文件SO71415908.gp

  • 在 Windows 命令行中输入 gnuplot -c SO71415908.gp,或者在 gnuplot 控制台中输入 加载“SO71415908.gp”。然而,在后一种情况下,我还没有找到如何在不关闭 gnuplot 的情况下关闭 Windows 控制台窗口。

脚本:

### create a BMP file with gnuplot via help of ImageMagick
reset session
set terminal pngcairo

FILE = "SO71415908"       # filename without extension

set output sprintf("%s.png",FILE)

plot sin(x)

set output      # close the file, necessary or not?

system sprintf('magick %s.png %s.bmp',FILE,FILE)
### end of code

结果:

两个文件:SO71415908.pngSO71415908.bmp

If I start the gnuplot console and set term windows and type plot sin(x) gnuplot is crashing. This is certainly a bug or something wrong with my system (Win10, gnuplot 5.4.1). I can only plot without crash if I set the terminal option to docked layout 1,1. But then, I get an empty BMP file like you got.

Actually, so far I haven't found any gnuplot version starting from 4.4.0 which seems to be able to create a correct BMP output.

So, then my suggestion would be to create a PNG output and convert this to BMP, e.g. via ImageMagick.

  • download and unzip the .zip version of ImageMagick

  • copy only the file magick.exe to your gnuplot working directory (or somewhere else where your system can find it)

  • save the script below into the file SO71415908.gp

  • either in Windows command line type gnuplot -c SO71415908.gp, or alternatively, in gnuplot console type load "SO71415908.gp". However, in the latter case I haven't found out how to close the Windows console windows without closing gnuplot.

Script:

### create a BMP file with gnuplot via help of ImageMagick
reset session
set terminal pngcairo

FILE = "SO71415908"       # filename without extension

set output sprintf("%s.png",FILE)

plot sin(x)

set output      # close the file, necessary or not?

system sprintf('magick %s.png %s.bmp',FILE,FILE)
### end of code

Result:

Two files: SO71415908.png and SO71415908.bmp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文