使用系統imgdecmp庫解碼JPG,GIF,PNG,BMP圖片

來源:互聯網
上載者:User

imgdecmp庫是WINCE 系統提供一個解碼BMP,GIF,PNG,JPG的檔案的庫,這個庫的缺陷是不能解出MASK 圖片.具體用法如下:

1.把imgdecmp.h加入工程,imgdecmp.h檔案內容如下:

/*---------------------------------------------------------------------------*/
 *
 * (c) Copyright Microsoft Corp. 1997-98 All Rights Reserved
 *
 *  module: imgdecmp.h
 *  date:
 *  author: jaym
 *
 *  purpose:
 *
/*---------------------------------------------------------------------------*/
#ifndef __IMGDECMP_H__
#define __IMGDECMP_H__

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#include "imgrendr.h"

typedef void (CALLBACK *PROGRESSFUNC)(IImageRender *pRender, BOOL bComplete, LPARAM lParam);
typedef DWORD (CALLBACK *GETDATAFUNC)(LPSTR szBuffer, DWORD dwBufferMax, LPARAM lParam);

typedef struct tagDecompressImageInfo {
 DWORD                   dwSize;                                 // Size of this structure
 LPBYTE                  pbBuffer;                               // Pointer to the buffer to use for data
 DWORD                   dwBufferMax;                    // Size of the buffer
 DWORD                   dwBufferCurrent;                // The amount of data which is current in the buffer
 HBITMAP *               phBM;                                   // Pointer to the bitmap returned (can be NULL)
 IImageRender ** ppImageRender;                  // Pointer to an IImageRender object (can be NULL)
 int                             iBitDepth;                              // Bit depth of the output image
 LPARAM                  lParam;                                 // User parameter for callback functions
 HDC                             hdc;                                    // HDC to use for retrieving palettes
 int                             iScale;                                 // Scale factor (1 - 100)
 int                             iMaxWidth;                              // Maximum width of the output image
 int                             iMaxHeight;                             // Maxumum height of the output image
 GETDATAFUNC             pfnGetData;                             // Callback function to get more data
 PROGRESSFUNC    pfnImageProgress;               // Callback function to notify caller of progress decoding the image
 COLORREF                crTransparentOverride;  // If this color is not (UINT)-1, it will override the
           // transparent color in the image with this color. (GIF ONLY)
} DecompressImageInfo;

#define IMGDECOMP_E_NOIMAGE             0x800b0100

COLORREF *
GetHalftonePalette();

COLORREF *
Get332Palette();

HRESULT
DecompressImageIndirect(DecompressImageInfo *pParams);

#ifdef __cplusplus
};
#endif // __cplusplus

#endif // !__IMGDECMP_H__

2.按照下面的方法使用.

HDC hdc = CreateCompatibleDC(NULL); 

DecompressImageInfo dii;

 BYTE    szBuffer[1024] = {0};
 HANDLE hFile = INVALID_HANDLE_VALUE;

// Fill in the 'DecompressImageInfo' structure
 dii.dwSize = sizeof( DecompressImageInfo );  // Size of this structure
 dii.pbBuffer = szBuffer;      // Pointer to the buffer to use for data
 dii.dwBufferMax = 1024;       // Size of the buffer
 dii.dwBufferCurrent = 0;      // The amount of data which is current in the buffer
 dii.phBM = &hBitmap;       // Pointer to the bitmap returned (can be NULL)
 dii.ppImageRender = NULL;      // Pointer to an IImageRender object (can be NULL)
 dii.iBitDepth = GetDeviceCaps(hdc,BITSPIXEL); // Bit depth of the output image
 dii.lParam = ( LPARAM ) &iCeBMPFile;//hFile;     // User parameter for callback functions
 dii.hdc = hdc;            // HDC to use for retrieving palettes
 dii.iScale = 100;          // Scale factor (1 - 100)
 dii.iMaxWidth = 10000;             // Maximum width of the output image
 dii.iMaxHeight = 10000;          // Maxumum height of the output image
 dii.pfnGetData = GetImageData;     // Callback function to get image data
 dii.pfnImageProgress = ImageProgress;   // Callback function to notify caller of progress decoding the image
 dii.crTransparentOverride = ( UINT ) -1;  // If this color is not (UINT)-1, it will override the
             // transparent color in the image with this color. (GIF ONLY)

 // Process and decompress the image data
 typedef HRESULT (CALLBACK* ULPRET)( DecompressImageInfo* pParams );

 HINSTANCE       hLib;
    ULPRET          lpfnDLLProc;

    hLib = LoadLibrary ( L"Imgdecmp.dll" );
    if ( hLib )
    {
       lpfnDLLProc = (ULPRET) GetProcAddress ( hLib, L"DecompressImageIndirect" );
       hr = (*lpfnDLLProc) ( &dii );
       FreeLibrary ( hLib );
    }

 // Clean up
 DeleteDC( hdc ); 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.