使用系统imgdecmp库解码JPG,GIF,PNG,BMP图片

 

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 ); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值