如何创建位图(用 C 语言)?

发布于 2024-08-14 03:12:59 字数 39 浏览 5 评论 0原文

我想知道如何在 C 中导入和导出位图。我基本上不知道从哪里开始。

I am wondering how I can both import and export bitmaps to and from C. I'm basically lost on where to begin.

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

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

发布评论

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

评论(7

飘然心甜 2024-08-21 03:12:59

内存中的位图看起来与此类似:

struct Image {
    int width;
    int height;
    char *data;    // 1 byte per channel & only 1 channel == grayscale
}

struct Image theImage;
theImage.width = 100;
theImage.height = 100;
theImage.data = malloc(sizeof(char) * theImage.width * theImage.height);

至于导入和导出,有一些非常简单的文件格式,请查看 BMP。对于更复杂的格式,您最好使用现有的库。

大多数框架已经提供了最常见文件格式的加载/保存方法。如果您正在寻找轻量级库,您可以查看 SDL

A bitmap in memory looks similar to this:

struct Image {
    int width;
    int height;
    char *data;    // 1 byte per channel & only 1 channel == grayscale
}

struct Image theImage;
theImage.width = 100;
theImage.height = 100;
theImage.data = malloc(sizeof(char) * theImage.width * theImage.height);

As to importing and exporting, there are some really simple file formats out there, take a look at BMP. For more complex formats you best use an already available library.

Most frameworks already have load/save methods for the most common fileformats. You could take a look at SDL if you're looking for a lightweight library.

飘过的浮云 2024-08-21 03:12:59

您看过 ImageMagick 的 C API 包装器吗,MagickWand< /a>? 如果您想仔细阅读,这里是文档。

Have you taken a look at ImageMagick's C API wrapper, MagickWand? Here's the documentation if you want to peruse.

梦里梦着梦中梦 2024-08-21 03:12:59

我喜欢将 SDL 与虚拟驱动程序一起使用。您可以像在屏幕上一样在内存缓冲区上绘图,然后将其保存为 PNG 或任何 SDL_image 或类似的。

另一个流行的库是 GD

I like using SDL with the dummy driver. You can draw onto an in-memory buffer just like you would onto a screen, then save it out to a PNG or whatever with SDL_image or similar.

Another popular library for this is GD.

贵在坚持 2024-08-21 03:12:59

简单的答案是使用合适的库。合适的库取决于您使用的平台。在 GUI 平台上,GUI API/框架将包含这些设施。

The simple answer is to use an appropriate library. What library is appropriate will depend on what platform you are using. On a GUI platform the GUI API/Framework will include these facilities.

瑕疵 2024-08-21 03:12:59

我喜欢 netpbm/pbmplus 工具,虽然我平时喜欢命令行; API 很高效,但使用起来不太有趣。

这个学期我编写了大量的软件供初学者用来操作图像;您可能想查看塔夫茨大学课程的作业和支持软件机器结构和组装-语言编程

I like the netpbm/pbmplus tools, although I usually like the command line; the API is efficient but not much fun to use.

This semester I wrote a significant amount of software for beginning students to use to manipulate images; you might want to check out the homework assignments and supporting software for the Tufts course Machine Structure and Assembly-Language Programming.

狼性发作 2024-08-21 03:12:59

术语“位图”有些通用,除非您特别指的是 Windows BMP

我建议在您的平台上使用图像处理库(例如 gd)。一个好的图形库具有对各种格式的图像进行输入和输出的例程。

The term "bitmap" is somewhat generic, unless you specifically mean a Windows BMP.

I'd recommend using an image processing library on your platform (like gd). A good graphics library has routines to do input and output with images in various formats.

时光清浅 2024-08-21 03:12:59

FreeImage 非常棒。我已将其用于我自己的游戏开发工作,它支持大量格式。以下是支持的功能和格式列表 - http://freeimage.sourceforge.net/features.html

FreeImage is excellent. I've used this for my own game development work, and it supports tons of formats. Here's the list of features and formats supported - http://freeimage.sourceforge.net/features.html

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