首页 > 其他分享 >FreeImage裁剪输出

FreeImage裁剪输出

时间:2024-10-10 11:05:01浏览次数:6  
标签:输出 960 1280 FreeImage 裁剪 bitmap int nWidth

#include <iostream>

#include"FreeImage.h"

bool    SaveToFile(int m_originW,int m_originH, char* FileName, BYTE* pBuf, int nWidth, int nHeight)
{
    
    
    FIBITMAP* bitmap = NULL;

    FREE_IMAGE_FORMAT fif = FIF_JPEG;
    int        flags = 0;
    
    fif = FIF_PNG;
        //flags |= PNG_Z_BEST_COMPRESSION;
    
        //flags |= JPEG_QUALITYSUPERB;
    
    bool    bRet = false;
    if ((m_originW < nWidth && m_originW >0) || (m_originH < nHeight && m_originH >0))
    {
        bitmap = FreeImage_ConvertFromRawBits(pBuf, m_originW, m_originH, nWidth * 3, 24, 8, 8, 8, true);
    }
    else {
        bitmap = FreeImage_ConvertFromRawBits(pBuf, nWidth, nHeight, nWidth * 3, 24, 8, 8, 8, true);
    }

    bRet = FreeImage_Save(fif, bitmap, FileName, flags);
    FreeImage_Unload(bitmap);

    
    return bRet;
}
int main()
{
    std::cout << "Hello World!\n";
    //960*1280
    FILE* originfp = fopen("image_960_1280.rgb24","rb+");
    
    if (originfp)
    {
        int64_t len = 960 * 1280 * 3;
        char* buf = new char[len];
        fread(buf,len ,1,originfp);
        char filename[20] = "D://ym.jpg";
        bool ret = SaveToFile(720, 1280, filename, (BYTE *)buf, 960, 1280);
        printf("ret: %d \n",ret);
    }
    return 0;

}

将960*1280的数据裁剪成720*1280

裁剪后涉及需要翻转一下,FreeImage有相应的flip接口;裁剪结果如下

 rgb图片:https://files.cnblogs.com/files/8335IT/image_960_1280.zip?t=1728529229&download=true

图片来源于网络微博;如有侵权,请及时评论联系 删除

标签:输出,960,1280,FreeImage,裁剪,bitmap,int,nWidth
From: https://www.cnblogs.com/8335IT/p/18455876

相关文章