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++代码,有点生疏 )

 

你可能感兴趣的:(CxImage的简单用法)