CxImage的简单用法

来源:互联网 发布:linux shell启动 编辑:程序博客网 时间:2024/05/22 03:33
#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++代码,有点生疏 )

 

原创粉丝点击