CxImage的简单用法

#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
#include "ximage.h"
#pragma comment(lib, "png.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "tiff.lib")
#pragma comment(lib, "jbig.lib")
#pragma comment(lib, "mng.lib")
#pragma comment(lib, "jasper.lib")
#pragma comment(lib, "libdcr.lib")
#pragma comment(lib, "libpsd.lib")
#pragma comment(lib, "cximage.lib")

void LoadFromMemory();
void LoadAndSaveFromFile();
void ReadKey();
int main()
{
    
    LoadFromMemory();
    ReadKey();
    return 0;
}

//这个函数是从内存文件中加载jpg并保存png文件
void LoadFromMemory()
{
    std::ifstream from("0015.jpg", ios::binary);
    if (!from)
    {
        cout << "Can't open file 0015.jpg" << endl;
        return;
    }

    int iFileLen = 0;
    streampos pos = from.tellg();
    from.seekg(0, ios::end);
    iFileLen = from.tellg();
    //cout << "File len : " << from.tellg() << endl;
    from.seekg(pos);
    BYTE *imageMemory = new BYTE[iFileLen];

    from.read((char*)imageMemory, iFileLen);
    CxImage image;//((TCHAR *)imageMemory, CXIMAGE_FORMAT_JPG);
    if (image.Decode(imageMemory, iFileLen, CXIMAGE_FORMAT_JPG))
    {
        cout << "Decode successfuly !" << endl;
    }
    image.Save("LoadInMemory.png",::CXIMAGE_FORMAT_PNG);
    from.close();
    delete []imageMemory;
}

//这个函数是从磁盘文件中加载jpg并保存png文件
void LoadAndSaveFromFile()
{
    ::CxImage *pImage = new CxImage;

    pImage->Load("0015.jpg",::CXIMAGE_FORMAT_JPG);
    pImage->Save("0015.png",::CXIMAGE_FORMAT_PNG);
}

void ReadKey()
{
    int a = 0;
    cin >> a;
}


下面代码演示CxImage从文件中加载图片和从内存中加载图片(很久没有写C++代码,有点生疏 )

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值