其他分享
首页 > 其他分享> > FreeImage图像格式转换

FreeImage图像格式转换

作者:互联网

由于opencv支持的图像格式有限,为了弥补这个不足,使用FreeImage进行格式转换。

基于磁盘文件的图像格式转换:

int main()
{
    FreeImage_Initialise();

    const char* srcImagePath = "E:/Desktop/01.tif";
    const char* dstImagePath = "E:/Desktop/01.png";

    int srcImageFormat = FreeImage_GetFIFFromFilename(srcImagePath);
    FIBITMAP *dib = FreeImage_Load(static_cast<FREE_IMAGE_FORMAT>(srcImageFormat), srcImagePath);
    if (dib == NULL)
    {
        cout << "图像加载失败" << endl;
        return 0;
    }

    unsigned int width = FreeImage_GetWidth(dib);    
    unsigned int height = FreeImage_GetHeight(dib);

    int dstImageFormat = FreeImage_GetFIFFromFilename(dstImagePath);
    if (!FreeImage_Save(static_cast<FREE_IMAGE_FORMAT>(dstImageFormat), dib, dstImagePath))
    {
        cout << "图像保存失败" << endl;
        return 0;
    }

    FreeImage_DeInitialise();

    return 0;
}

基于内存的图像格式转换:

 

标签:图像格式,转换,cout,FreeImage,dib,srcImagePath
来源: https://www.cnblogs.com/nanfei/p/14314485.html