首页 > 其他 > 详细

FreeImage图像格式转换

时间:2021-01-22 19:27:39      阅读:30      评论:0      收藏:0      [点我收藏+]

由于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;
}

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

 

FreeImage图像格式转换

原文:https://www.cnblogs.com/nanfei/p/14314485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!