哪位有BMP<->Jpg,Gif,Pcx等的源代码?
我的信箱:[email protected]
谢谢!

解决方案 »

  1.   

    建议你去找《Visual C++.net图象处理编程》这本书看看。
      

  2.   

    我有BMP<--->JPEG的程序。
    是采用intel JPEG library 要的话,给我发邮件 [email protected]
      

  3.   

    http://www.codeguru.com
    http://www.codeproject.com
      

  4.   

    #include <Stdio.h>
    #include <Objbase.h>
    #include <Windows.h>
    #include <Gdiplus.h>
    #include <GdiPlusEnums.h>
    using namespace Gdiplus;
    #pragma comment(lib,"gdiplus")
    // Helper functions
    int GetCodecClsid(const WCHAR*, CLSID*);
    HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW)
    {
        ULONG cCharacters;
        DWORD dwError;
        if (NULL == pszA)
        {
            *ppszW = NULL;
            return NOERROR;
        }
        cCharacters =  strlen(pszA)+1;
        *ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);
        if (NULL == *ppszW)
            return E_OUTOFMEMORY;
        if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,*ppszW, cCharacters))
        {
            dwError = GetLastError();
            CoTaskMemFree(*ppszW);
            *ppszW = NULL;
            return HRESULT_FROM_WIN32(dwError);
        }    return NOERROR;
    }
    int main(int argc, char* argv[])
    {
    int n_ret=0;
    printf("%s can convert jpg, png, gif, tiff to bmp file.\n if it works, it is written by masterz, otherwise I don't know who write it",argv[0]);
    if(argc!=3)
    {
    printf("usage:%s bmp_filename source_image_filename\n",argv[0]);
    return -1;
    }
    GdiplusStartupInput gdiplusStartupInput; 
    ULONG gdiplusToken; 
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 
    {
    CLSID              codecClsid;
    Status             stat;
    EncoderParameters  encoderParameters; GetCodecClsid(L"image/bmp", &codecClsid);
    encoderParameters.Count = 0;
    LPOLESTR bstr_src_img;
    LPOLESTR bstr_dst_bmp;
    AnsiToUnicode(argv[1],&bstr_dst_bmp);
    AnsiToUnicode(argv[2],&bstr_src_img);
    Image image(bstr_src_img);
    stat =image.Save(bstr_dst_bmp, &codecClsid, &encoderParameters);
    if(stat == Ok)
    {
    n_ret=0;
    wprintf(L"%s saved successfully.\n",bstr_dst_bmp);
    }
    else
    {
    n_ret=-2;
    wprintf(L"%d  Attempt to save %s failed.\n", stat, bstr_dst_bmp);
    }
    CoTaskMemFree(bstr_dst_bmp);
    CoTaskMemFree(bstr_src_img);
    }
    GdiplusShutdown(gdiplusToken);
    return 0;
    } // main
    int GetCodecClsid(const WCHAR* format, CLSID* pClsid)
    {
       UINT  num = 0;          // number of image encoders
       UINT  size = 0;         // size of the image encoder array in bytes   ImageCodecInfo* pImageCodecInfo = NULL;   GetImageEncodersSize(&num, &size);
       if(size == 0)
          return -1;  // Failure   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
       if(pImageCodecInfo == NULL)
          return -1;  // Failure   GetImageEncoders(num, size, pImageCodecInfo);   for(UINT j = 0; j < num; ++j)
       {
          if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
          {
             *pClsid = pImageCodecInfo[j].Clsid;
             return j;  // Success
          }    
       } // for   return -1;  // Failure} // GetCodecClsid
    //in order to compile this program, you need to download microsoft platform sdk from http://www.microsoft.com/msdownload/platformsdk/sdkupdate/downlevel.htm
    //also download gdiplus.dll and put it at the same directory as the executable.
    //http://www.microsoft.com/downloads/release.asp?releaseid=32738
    //Platform SDK Redistributable: GDI+ RTM
      

  5.   

    convert image to GIF via GDI+
    #include <Stdio.h>
    #include <Objbase.h>
    #include <Windows.h>
    #include <Gdiplus.h>
    #include <GdiPlusEnums.h>
    using namespace Gdiplus;
    #pragma comment(lib,"gdiplus")
    int GetCodecClsid(const WCHAR*, CLSID*);
    HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW)
    {
        ULONG cCharacters;
        DWORD dwError;
        if (NULL == pszA)
        {
            *ppszW = NULL;
            return NOERROR;
        }
        cCharacters =  strlen(pszA)+1;
        *ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);
        if (NULL == *ppszW)
            return E_OUTOFMEMORY;
        if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,*ppszW, cCharacters))
        {
            dwError = GetLastError();
            CoTaskMemFree(*ppszW);
            *ppszW = NULL;
            return HRESULT_FROM_WIN32(dwError);
        }
        return NOERROR;
    }int main(int argc, char* argv[])
    {
    int n_ret=0;
    printf("%s can convert jpg, png, gif, tiff to gif file.\n if it works, it is written by masterz, otherwise I don't know who write it\n",argv[0]);
    if(argc!=3)
    {
    printf("usage:%s gif_filename source_image_filename\n",argv[0]);
    return -1;
    }
    GdiplusStartupInput gdiplusStartupInput; 
    ULONG gdiplusToken; 
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 
    {
    CLSID              codecClsid;
    Status             stat;
    EncoderParameters  encoderParameters; GetCodecClsid(L"image/gif", &codecClsid);
    encoderParameters.Count = 0;
    LPOLESTR bstr_src_img;
    LPOLESTR bstr_dst_fn;
    AnsiToUnicode(argv[1],&bstr_dst_fn);
    AnsiToUnicode(argv[2],&bstr_src_img);
    Image image(bstr_src_img);
    stat =image.Save(bstr_dst_fn, &codecClsid, &encoderParameters);
    if(stat == Ok)
    {
    n_ret=0;
    wprintf(L"%s saved successfully.\n",bstr_dst_fn);
    }
    else
    {
    n_ret=-2;
    wprintf(L"%d  Attempt to save %s failed.\n", stat, bstr_dst_fn);
    }
    CoTaskMemFree(bstr_dst_fn);
    CoTaskMemFree(bstr_src_img);
    }
    GdiplusShutdown(gdiplusToken);
    return 0;
    } // main
    int GetCodecClsid(const WCHAR* format, CLSID* pClsid)
    {
       UINT  num = 0;          // number of image encoders
       UINT  size = 0;         // size of the image encoder array in bytes   ImageCodecInfo* pImageCodecInfo = NULL;   GetImageEncodersSize(&num, &size);
       if(size == 0)
          return -1;  // Failure   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
       if(pImageCodecInfo == NULL)
          return -1;  // Failure   GetImageEncoders(num, size, pImageCodecInfo);   for(UINT j = 0; j < num; ++j)
       {
          if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
          {
             *pClsid = pImageCodecInfo[j].Clsid;
             return j;  // Success
          }    
       } // for   return -1;  // Failure} // GetCodecClsid
    //in order to compile this program, you need to download microsoft platform sdk from http://www.microsoft.com/msdownload/platformsdk/sdkupdate/downlevel.htm
    //also download gdiplus.dll and put it at the same directory as the executable.
    //http://www.microsoft.com/downloads/release.asp?releaseid=32738
    //Platform SDK Redistributable: GDI+ RTM
      

  6.   

    convert BMP->JPG via GDI+
    #include <Stdio.h>
    #include <Objbase.h>
    #include <Windows.h>
    #include <Gdiplus.h>
    #include <GdiPlusEnums.h>
    using namespace Gdiplus;
    #pragma comment(lib,"gdiplus")
    // Helper functions
    int GetCodecClsid(const WCHAR*, CLSID*);int main()
    {
    CLSID              codecClsid;
    EncoderParameters  encoderParameters;
    long               quality;
    Status             stat;
    GdiplusStartupInput gdiplusStartupInput; 
    ULONG gdiplusToken; 
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 
    {
    // Get an image from the disk.
    Image image(L"F:\\ddd.bmp");

    // Get the CLSID of the JPEG codec.
    GetCodecClsid(L"image/jpeg", &codecClsid);

    // Before we call Image::Save, we must initialize an
    // EncoderParameters object. The EncoderParameters object
    // has an array of EncoderParameter objects. In this
    // case, there is only one EncoderParameter object in the array.
    // The one EncoderParameter object has an array of values.
    // In this case, there is only one value (of type LONG)
    // in the array. We will set this value to 0, 50, and 100.

    encoderParameters.Count = 1;
    encoderParameters.Parameter[0].Guid = EncoderQuality;
    encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
    encoderParameters.Parameter[0].NumberOfValues = 1;

    // Save the image as a JPEG with quality level 0.
    quality = 0;
    encoderParameters.Parameter[0].Value = &quality;
    stat = image.Save(L"Shapes001.jpg", &codecClsid, &encoderParameters);

    if(stat == Ok)
    wprintf(L"%s saved successfully.\n", L"Shapes001.jpg");
    else
    wprintf(L"%d  Attempt to save %s failed.\n", stat, L"Shapes001.jpg");

    // Save the image as a JPEG with quality level 50.
    quality = 50;
    encoderParameters.Parameter[0].Value = &quality;
    stat = image.Save(L"Shapes050.jpg", &codecClsid, &encoderParameters);

    if(stat == Ok)
    wprintf(L"%s saved successfully.\n", L"Shapes050.jpg");
    else
    wprintf(L"%d  Attempt to save %s failed.\n", stat, L"Shapes050.jpg");

    // Save the image as a JPEG with quality level 100.
    quality = 100;
    encoderParameters.Parameter[0].Value = &quality;
    stat = image.Save(L"Shapes100.jpg", &codecClsid, &encoderParameters);

    if(stat == Ok)
    wprintf(L"%s saved successfully.\n", L"Shapes100.jpg");
    else
    wprintf(L"%d  Attempt to save %s failed.\n", stat, L"Shapes100.jpg");
    }
    GdiplusShutdown(gdiplusToken);
    return 0;
    } // main
    int GetCodecClsid(const WCHAR* format, CLSID* pClsid)
    {
       UINT  num = 0;          // number of image encoders
       UINT  size = 0;         // size of the image encoder array in bytes   ImageCodecInfo* pImageCodecInfo = NULL;   GetImageEncodersSize(&num, &size);
       if(size == 0)
          return -1;  // Failure   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
       if(pImageCodecInfo == NULL)
          return -1;  // Failure   GetImageEncoders(num, size, pImageCodecInfo);   for(int j = 0; j < num; ++j)
       {
          if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
          {
             *pClsid = pImageCodecInfo[j].Clsid;
             return j;  // Success
          }    
       } // for   return -1;  // Failure} // GetCodecClsid
    //download gdiplus.dll 
    //http://www.microsoft.com/downloads/release.asp?releaseid=32738
    //Platform SDK Redistributable: GDI+ RTM
      

  7.   

    http://www.paintlib.de/paintlib/
    paintlib is a portable C++ class library for image loading, saving and manipulation. Images can be loaded from BMP, GIF, JPEG, PCX, PGM, PICT, PNG, TGA, TIFF and WMF files and saved in BMP, JPEG, PNG and TIFF formats. (copyrighted open source software)
      

  8.   

    http://www.paintlib.de/paintlib/
    paintlib is a portable C++ class library for image loading, saving and manipulation. Images can be loaded from BMP, GIF, JPEG, PCX, PGM, PICT, PNG, TGA, TIFF and WMF files and saved in BMP, JPEG, PNG and TIFF formats. (copyrighted open source software)