C/C++图片加载

发布于 2024-09-10 12:01:22 字数 1539 浏览 5 评论 0原文

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

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

发布评论

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

评论(7

无人问我粥可暖 2024-09-17 12:01:23

最初开发的有Boost的GIL由 Adob​​e 提供。它可能不是最直观的,但它肯定是最完整、最强大的库之一。

There is Boost's GIL which was originally developed by Adobe. It might not be the most intuitive one, but it certainly is one of the most complete and powerful libs.

泪冰清 2024-09-17 12:01:23

如果您使用 OpenGL,那么 DevIL 是一个不错的选择,因为它的风格和约定比任何其他图书馆。它的设置相对容易,并且对多种格式有很好的支持。

关于懦弱的事情的一件事。虽然设置经过充分测试的可运行的第 3 方代码很好,并且可以节省您的时间,但也有一些关于学习图像加载的工作原理以及其工作原理的原因。如果你真的想擅长某件事,我相信你需要从头开始学习如何去做。即使您最终使用了第三方代码。

If you're using OpenGL, then DevIL is a good choice since its style and conventions adhere to OpenGL more than any other library. It's relatively easy to set up and also has great support for multiple formats.

One thing about the wuss thing. While it's nice to set up working 3rd party code that has been well tested and saves you time, there's something to be also said about learning how image loading works and why it works the way it does. If you really want to get good at something, I believe that you need to actually learn how to do it from scratch. Even if you end up using 3rd party code in the end.

无尽的现实 2024-09-17 12:01:23

您可以查看 SDL_Image,它是 简单的 DirectMedia 层。它作为加载几种不同图像格式的简单抽象。 SDL 是用 C 语言编写的,但很容易与 C 或 C++ 代码一起使用。

You could have a look at SDL_Image, a sub-project of the Simple DirectMedia Layer. It serves as an easy abstraction for loading several different image formats. SDL is written in C but is easy to use with either C or C++ code.

梦里°也失望 2024-09-17 12:01:23

另一种可能性(主要是,如果不是专门用于 Windows)是 CXImage。与许多其他格式相比,它的明显优势是支持多种相机原始格式(如果您对此很重要)。

Yet another possibility (primarily, if not exclusively for Windows) is CXImage. Its obvious advantage over many others is supporting many camera raw formats, in case that matters to you.

潦草背影 2024-09-17 12:01:23

OpenImageIO 支持多种不同的文件格式,其中包括 TIFF、JPEG/JFIF、OpenEXR、PNG、HDR/RGBE、ICO、BMP 、Targa、JPEG-2000、RMan Zfile、FITS、DDS、Softimage PIC、PNM、DPX、Cineon、IFF、Field3D、Ptex、Photoshop PSD、Wavefront RLA、SGI、WebP 和 GIF

OpenImageIO supports many different file formats among them TIFF, JPEG/JFIF, OpenEXR, PNG, HDR/RGBE, ICO, BMP, Targa, JPEG-2000, RMan Zfile, FITS, DDS, Softimage PIC, PNM, DPX, Cineon, IFF, Field3D, Ptex, Photoshop PSD, Wavefront RLA, SGI, WebP, and GIF

御弟哥哥 2024-09-17 12:01:22

我一直是 CImg 的粉丝。它非常容易使用。另一位用户喜欢答案:出色地。我将发布我在答案中发布的相同示例,以便您可以看到访问像素和尺寸信息是多么容易。

CImg<unsigned char> src("image.jpg");
int width = src.width();
int height = src.height();
unsigned char* ptr = src.data(10,10); // get pointer to pixel @ 10,10
unsigned char pixel = *ptr;

I'm always a fan of CImg. It's very easy to use. Another user liked the answer as well. I'll post the same example I posted in the answer so you can see how easy it is to access pixels and dimension info.

CImg<unsigned char> src("image.jpg");
int width = src.width();
int height = src.height();
unsigned char* ptr = src.data(10,10); // get pointer to pixel @ 10,10
unsigned char pixel = *ptr;
枕梦 2024-09-17 12:01:22

FreeImage 是一个很好的开源库

这是一个示例代码,可以通过“out.data()”访问数据

FREE_IMAGE_FORMAT format = FreeImage_GetFileTypeU(filename.c_str());
if (format == FIF_UNKNOWN)      format = FreeImage_GetFIFFromFilenameU(filename.c_str());
if (format == FIF_UNKNOWN)      throw(std::runtime_error("File format not supported"));

FIBITMAP* bitmap = FreeImage_LoadU(format, filename.c_str());
FIBITMAP* bitmap2 = FreeImage_ConvertTo32Bits(bitmap);
FreeImage_Unload(bitmap);

std::vector<char> out(FreeImage_GetWidth(bitmap2) * FreeImage_GetHeight(bitmap2) * 4);
FreeImage_ConvertToRawBits((BYTE*)out.data(), bitmap2, FreeImage_GetWidth(bitmap2) * 4, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true);

FreeImage_Unload(bitmap2);

FreeImage is a good open source library

Here is an example code, data is accessible with "out.data()"

FREE_IMAGE_FORMAT format = FreeImage_GetFileTypeU(filename.c_str());
if (format == FIF_UNKNOWN)      format = FreeImage_GetFIFFromFilenameU(filename.c_str());
if (format == FIF_UNKNOWN)      throw(std::runtime_error("File format not supported"));

FIBITMAP* bitmap = FreeImage_LoadU(format, filename.c_str());
FIBITMAP* bitmap2 = FreeImage_ConvertTo32Bits(bitmap);
FreeImage_Unload(bitmap);

std::vector<char> out(FreeImage_GetWidth(bitmap2) * FreeImage_GetHeight(bitmap2) * 4);
FreeImage_ConvertToRawBits((BYTE*)out.data(), bitmap2, FreeImage_GetWidth(bitmap2) * 4, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true);

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