Use the system imgdecmp library to decode JPG, GIF, PNG, and BMP Images

Source: Internet
Author: User
Tags transparent color

The imgdecmp library is a library provided by the wince system to decode BMP, GIF, PNG, and jpg files. The defect of this library is that it cannot solve the mask image. The usage is as follows:

1. Add imgdecmp. H to the project. The imgdecmp. h file content is as follows:

/*---------------------------------------------------------------------------*/
*
* (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 );
Typedef DWORD (callback * getdatafunc) (lpstr szbuffer, DWORD dwbuffermax, 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; // USER parameter for callback Functions
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 y caller of progress decoding the image
Colorref crtransparentoverride; // if this color is not (uint)-1, it will override
// 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. Use the following method.

HDC = createcompatibledc (null );

Decompressimageinfo DiI;

Byte szbuffer [1024] = {0 };
Handle hfile = invalid_handle_value;

// Fill in the 'describeinfo' 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 callback y caller of progress decoding the image
Dii. crtransparentoverride = (uint)-1; // if this color is not (uint)-1, it will override
// 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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.