如何创建位图(用 C 语言)?
我想知道如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
内存中的位图看起来与此类似:
至于导入和导出,有一些非常简单的文件格式,请查看 BMP。对于更复杂的格式,您最好使用现有的库。
大多数框架已经提供了最常见文件格式的加载/保存方法。如果您正在寻找轻量级库,您可以查看 SDL 。
A bitmap in memory looks similar to this:
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.
您看过 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.
我喜欢将 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.
简单的答案是使用合适的库。合适的库取决于您使用的平台。在 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.
我喜欢 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.
术语“位图”有些通用,除非您特别指的是 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.
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