将数值二维数组保存到图像

发布于 2024-10-05 20:48:19 字数 268 浏览 9 评论 0原文

最近,我一直在用 C 语言进行一些数值方法编程。对于错误修复和故障排除,最好能对正在发生的情况进行一些可视化表示。到目前为止,我一直将数组区域输出到标准输出,但这并没有提供那么多信息。我也一直在玩弄 gnuplot,但我无法得到它,只保存图像,而不是坐标系和所有其他东西。

所以我正在寻找一个教程或者一个库来向我展示如何将数组从 c 保存到图像中,如果能够保存到彩色图像,那就太好了。从数值到颜色的转换不是问题,我可以计算出来。如果有人能向我指出该领域一些有用的库的方向,那就太好了。

此致

Lately I have been doing some numerical method programming in C. For the bug fixing and throubleshooting it's nice to have some visual representation of what is happening. So far I have been outputting areas of array to the standard output, but that doesn't give that much information. I have also been playing around a bit with gnuplot, but I can't get it too save only image, not the coordinate system and all the other stuff.

So I am looking for a tutorial or maybe a library to show me how to save array from c into an image, it would be especially nice to be possible to save to color images. The transformation from numerical value to a color is not a problem, I can calculate that. It would just be nice of someone to point me in the direction of some useful libraries in this field.

best regards

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

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

发布评论

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

评论(1

方觉久 2024-10-12 20:48:19

您可以使用 .ppm 文件格式...它非常简单,不需要任何库...

FILE *f = fopen("out.ppm", "wb");
fprintf(f, "P6\n%i %i 255\n", width, height);
for (int y=0; y<height; y++) {
    for (int x=0; x<width; x++) {
        fputc(red_value, f);   // 0 .. 255
        fputc(green_value, f); // 0 .. 255
        fputc(blue_value, f);  // 0 .. 255
    }
}
fclose(f);

You could use the .ppm file format... it's so simple that no library is necessary...

FILE *f = fopen("out.ppm", "wb");
fprintf(f, "P6\n%i %i 255\n", width, height);
for (int y=0; y<height; y++) {
    for (int x=0; x<width; x++) {
        fputc(red_value, f);   // 0 .. 255
        fputc(green_value, f); // 0 .. 255
        fputc(blue_value, f);  // 0 .. 255
    }
}
fclose(f);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文