码迷,mamicode.com
首页 > 其他好文 > 详细

FreeImage裁剪示例

时间:2015-08-05 14:24:07      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

//截图
int cropImage(const char* file, int left, int top, int right, int bottom, BYTE* &dstData, DWORD& dstLen)
{
    DWORD dw1 = GetTickCount();
    fipImage image;
    BOOL bSuccess = image.load(file);
    if ( !bSuccess )
    {
        printf("image.load fail\n");
        return -1;
    }
    //bSuccess = image.crop(0, 0, 300, 200);
    bSuccess = image.crop(left, top, right, bottom);
    if ( !bSuccess )
    {
        printf("image.crop fail\n");
        return -1;
    }

    // fipImage -> fipMenoryIO
    fipMemoryIO memIO;
    bSuccess = image.saveToMemory(FIF_JPEG, memIO, JPEG_DEFAULT);
    if ( !bSuccess )
    {
        printf("image.saveToMemory fail\n");
        return -1;
    }

    // fipMemoryIO -> char*
    BYTE* srcData = NULL;;
    DWORD size_in_bytes = 0;
    bSuccess = memIO.acquire(&srcData, &size_in_bytes);
    if ( !bSuccess )
    {
        printf("memIO.acquire fail\n");
        return -1;
    }

    DWORD dw2 = GetTickCount() - dw1;
    printf("%u\n", dw2);

    dstLen = size_in_bytes;
    BYTE* data = new BYTE[dstLen];
    memcpy(data, srcData, dstLen);
    dstData = data;
    //    bSuccess = image.save("crop.jpg");
    return 0;
}

//函数使用
BYTE* data = NULL;;
DWORD dataLen = 0;
cropImage(lpszTestFile, 0, 0, 300, 200, data, dataLen);

 

FreeImage裁剪示例

标签:

原文地址:http://www.cnblogs.com/jingdian1956/p/4704415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!