• CxImage简单用法2


    从CxImage中将xfile.h、ximacfg.h、ximadef.h、ximage.cpp、ximage.h、xiofile.h、xmemfile.cpp、xmemfile.h拷贝到工程文件夹下并将这些文件加入工程,然后将CxImage各文件夹下Debug文件夹中的lib文件也拷贝到工程下,并在VC中做如下设置  
       
      Project   Settings  
      |-   C/C++  
      |       |-   Code   Generation  
      |       |       |-   Use   run-time   library   :   Multithreaded   DLL   (must   be   the   same   for    
      |       |       |     all   the   linked   libraries)     //应该只要是多线程DLL即可,DEBUG的也行  
      |       |       |-   Struct   member   alignment   :   must   be   the   same   for   all   the   linked   libraries  
      |       |-   Precompiled   headers   :   not   using   precompiled   headers  
      |       |-   Preprocessor  
      |               |-   Additional   Include   Directories:     ..\cximage(该处填CxImage里的.h和.cpp文件拷贝并导入工程后所在的文件夹,填写后在工程中include时编译器会查找该文件夹,故include的文件无需路径)  
      |-   Link  
              |-   General  
                      |-   Object/library   modules:   ../png/Debug/png.lib    
                                                                            ../jpeg/Debug/jpeg.lib    
                                                                            ../zlib/Debug/zlib.lib    
                                                                            ../tiff/Debug/tiff.lib    
                                                                            ../jasper/Debug/jasper.lib    
                                                                              ../cximage/Debug/cximage.lib     (前面的路径设为从CxImage中拷贝到工程中的lib文件所在的目录)  
       
      要在picture   box中显示一个png格式的文件,只需:  
      CxImage   image("myfile.png",   CXIMAGE_FORMAT_PNG);  
      HBITMAP   m_bitmap   =   image.MakeBitmap(m_picture.GetDC()->m_hDC);  
      m_picture.SetBitmap(m_bitmap);  
      其它格式则类推。  
      Examples:   how   to   ...  
      ...   convert   from   a   format   to   another  
      CxImage     image;  
      //   bmp   ->   jpg  
      image.Load("image.bmp",   CXIMAGE_FORMAT_BMP);  
      if   (image.IsValid()){  
      if(!image.IsGrayScale())   image.IncreaseBpp(24);  
      image.SetJpegQuality(99);  
      image.Save("image.jpg",CXIMAGE_FORMAT_JPG);  
      }  
      //   png   ->   tif  
      image.Load("image.png",   CXIMAGE_FORMAT_PNG);  
      if   (image.IsValid()){  
      image.Save("image.tif",CXIMAGE_FORMAT_TIF);  
      }  
      ...   load   an   image   resource  
      //Load   the   resource   IDR_PNG1   from   the   PNG   resource   type  
      CxImage*   newImage   =   new   CxImage();  
      newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG1),  
      "PNG"),CXIMAGE_FORMAT_PNG);  
      or//Load   the   resource   IDR_JPG1   from   DLL  
      CxImage*   newImage   =   new   CxImage();  
      HINSTANCE   hdll=LoadLibrary("imagelib.dll");  
      if   (hdll){  
      HRSRC   hres=FindResource(hdll,MAKEINTRESOURCE(IDR_JPG1),"JPG");  
      newImage->LoadResource(hres,CXIMAGE_FORMAT_JPG,hdll);  
      FreeLibrary(hdll);  
      }  
      or//Load   a   bitmap   resource;  
      HBITMAP   bitmap   =   ::LoadBitmap(AfxGetInstanceHandle(),  
      MAKEINTRESOURCE(IDB_BITMAP1)));  
      CxImage   *newImage   =   new   CxImage();  
      newImage->CreateFromHBITMAP(bitmap);  
      ...   decode   an   image   from   memory  
      CxImage   image((BYTE*)buffer,size,image_type);  
      orCxMemFile   memfile((BYTE*)buffer,size);  
      CxImage   image(&memfile,image_type);  
      orCxMemFile   memfile((BYTE*)buffer,size);  
      CxImage*   image   =   new   CxImage();  
      image->Decode(&memfile,type);  
      ...   encode   an   image   in   memory  
      long   size=0;  
      BYTE*   buffer=0;  
      image.Encode(buffer,size,image_type);  
      ...  
      free(buffer);  
      orCxMemFile   memfile;  
      memfile.Open();  
      image.Encode(&memfile,image_type);  
      BYTE*   buffer   =   memfile.GetBuffer();  
      long   size   =   memfile.Size();  
      ...  
      free(buffer);  
      ...   create   a   multipage   TIFF  
      CxImage   *pimage[3];  
      pimage[0]=&image1;  
      pimage[1]=&image2;  
      pimage[2]=&image3;  
      FILE*   hFile;  
      hFile   =   fopen("multipage.tif","w+b");  
      CxImageTIF   multiimage;  
      multiimage.Encode(hFile,pimage,3);  
      fclose(hFile);  
      orFILE*   hFile;  
      hFile   =   fopen("c:\\multi.tif","w+b");  
      CxImageTIF   image;  
      image.Load("c:\\1.tif",CXIMAGE_FORMAT_TIF);  
      image.Encode(hFile,true);  
      image.Load("c:\\2.bmp",CXIMAGE_FORMAT_BMP);  
      image.Encode(hFile,true);  
      image.Load("c:\\3.png",CXIMAGE_FORMAT_PNG);  
      image.Encode(hFile);  
      fclose(hFile);  
      ...   copy/paste   an   image  
      //copy  
      HANDLE   hDIB   =   image->CopyToHandle();  
      if   (::OpenClipboard(AfxGetApp()->m_pMainWnd->GetSafeHwnd()))   {  
      if(::EmptyClipboard())   {  
      if   (::SetClipboardData(CF_DIB,hDIB)   ==   NULL   )   {  
      AfxMessageBox(   "Unable   to   set   Clipboard   data"   );  
      }         }         }  
      CloseClipboard();  
      //paste  
      HANDLE   hBitmap=NULL;  
      CxImage   *newima   =   new   CxImage();  
      if   (OpenClipboard())   hBitmap=GetClipboardData(CF_DIB);  
      if   (hBitmap)   newima->CreateFromHANDLE(hBitmap);  
      CloseClipboard();  
      需要大家注意的是:整个CxImage类库非常大。如果你只需要能处理其中的几种格式,你可以在主要的头文件ximage.h中找到一些开关选项来关闭一些图像库。JPG、PNG、TIFF中的每一个库,都会向最终程序增加约100KB的内容。而CxImage类库压缩后只有约60KB。所以,你需要谨慎挑选一些你真正需要的类库。作者提供的示例工程在编译后,你会发现如下一些文件:   ·CxImage   :   cximage.lib   -   static   library   ·CxImageCrtDll   :   cximagecrt.dll   -   DLL   not   using   mfc   ·CxImageMfcDll   :   cximage.dll   -   DLL   using   mfc   ·Demo   :   demo.exe   -   program   linked   with   cximage.lib   and   the   C   libraries   ·DemoDll   :   demodll.exe   -   program   linked   with   cximagecrt.dll   ·j2k,jasper,jbig,jpeg,png,tiff,zlib   :   static   C   libraries   构建这些工程需要耗费几分钟的时间(中间文件可达60MB)。

  • 相关阅读:
    使用jquery.validate.js实现boostrap3的校验和验证
    MySQL 随机取数据效率问题
    qq在线客服代码
    使用Shell脚本查找程序对应的进程ID,并杀死进程
    Redis-概述
    JVM的类加载机制
    volatile
    java内存相关
    设计模式--模板方法
    设计模式概述
  • 原文地址:https://www.cnblogs.com/buffer/p/1410240.html
Copyright © 2020-2023  润新知