C++loadimage
时间: 2023-07-11 08:12:18 浏览: 109
在 C++ 中,你可以使用许多库来加载图像。以下是一些常用的库和简单示例代码:
- 使用 GDI+ 库加载图像:
#include <Windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
int main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Bitmap* bmp = Bitmap::FromFile(L"path/to/image.jpg");
if (bmp != NULL)
{
// 在此处使用位图
delete bmp;
}
GdiplusShutdown(gdiplusToken);
return 0;
}
- 使用 OpenCV 库加载图像:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img = imread("path/to/image.jpg");
if (!img.empty())
{
// 在此处使用图像
}
return 0;
}
- 使用 FreeImage 库加载图像:
#include <FreeImage.h>
#pragma comment(lib, "FreeImage.lib")
int main()
{
FreeImage_Initialise();
FIBITMAP* bmp = FreeImage_Load(FIF_JPEG, "path/to/image.jpg", JPEG_DEFAULT);
if (bmp != NULL)
{
// 在此处使用位图
FreeImage_Unload(bmp);
}
FreeImage_DeInitialise();
return 0;
}
请注意,这些示例代码仅用于加载图像。如果你需要对图像进行进一步操作,还需要使用相应的库函数。
相关推荐
















