Author: Ma Jian E-mail: stronghorse@tom.com home page: http: //stronghorse.yeah.net
First, why do IIMGCTX perform image decoding?
When the image is developed under Windows, the first step is to face when the image processing software is image decoding. The current free image decoding code is a lot, separately includes:
Independent Jpeg Group released the source code of the source code for the source code for the source code of the libpng organization provides the source code of the source code of the LibTIFF organization.
If you think one, one goes to find these source code too much, you can also use the CxImage developed by Davide Pizzolato, which integrates a decoding source code for most common image formats.
But after I used these source code, I found some questions:
It is too much trouble, not only when compiling, it needs to be set to compile parameters, but also the decoded image is also troublesome. Reliability is doubtful, and after the error, tracking, debugging is too difficult, that big pile C code is not fun. All decoding code requires embedded EXE files generated after compiled, or DLL, adds the size of the final issued package. Of course, if the end user wants to make a "large software", it is another matter.
So I am like some other "lazy" programmer, I hope to find a general-purpose image decoder that is easy to use like a Windows API, which is convenient and generated.
Based on the information I saw online, I first consider the iPicture interface provided by Windows itself. This interface has a very detailed description in MSDN, and there is also a detailed example of a detailed example on CodeGuru and CodeProject, which is very convenient. It is a pity that this interface can only decode the image of BMP, WMF, ICO, GIF, JPG format (public document only recognizes BMP, WMF, ICO), is invalid to PNG, TIFF format.
Later, when I installed the Windows system, I found that the GIF, PNG, and JPG files under Windows were associated with the IE browser. Think about it, so IE supports them. Nothing is so strange. Then there is no interface to the IE kernel, it is like IHTMLDocument to resolve the HTML source code, can we provide us with image decoding?
The answer is: Some, it is the IIMGCTX interface. This interface can decode all image formats that can be displayed in IE, including JPG, PNG, GIF, BMP, WMF, ICO, sometimes to solve Tiff (later I explain why "Sometimes").
Second, how to use IIMGCTX to perform image decoding?
In my hand IE 5.5 SDK package, there is a complete definition of the IIMGCTX interface (in the IImgctx.h file), in the installation directory of the VC 6, the definition, file name, the file content is only poor. One line: IE 5.5 SDK package has defined a constant DWN_MirrorImage, estimating that IE 5.5 is more than IE 4, can be mirrored to the decoded image.
But don't say it in MSDN, even if you use Google Search, you can't find any instructions for this interface. Fortunately, this interface is relatively simple, and the interface definition can also guess its usage:
Declare_INTERFACE_ (IIMGCTX, IUNKNOWN)
{
#ifndef no_baseinterface_funcs
/ * IUnknown methods * /
STDMETHOD (THIS_ REFIID RIID, LPVOID FAR * PPVOBJ) PURE
STDMETHOD_ (ULONG, ADDREF) PURE
STDMETHOD_ (ULONG, RELEASE) PURE
#ENDIF
/ * IIMGCTX METHODS * /
/ * Initialization / DownloadMETHODS * /
Stdmethod (THIS_ LPCWSTR PSZURL, DWORD DWFLAGS) PURE
STDMETHOD (SELECTCHANGES) (Ulong ulchgoff, bool fsignal) Pure;
STDMETHOD (THIS_ PFNIMGCTXCALLBACK PFN, VOID * PVPRIVATEDATA) PURE
STDMETHOD (THIS) PURE
/ * Query methods * /
STDMETHOD (THIS_ STRUCT TAGRECT FAR * PRC, STRUCT TAGRECT FAR * PRCIMG, Long Far * PCRC) PURE
Stdmethod (THISTATEINFO) (Struct Tagsize Far * Psize, Bool Fclearchange) Pure;
STDMETHOD (THIS_HPALETTE FAR * PHPAL) PURE
/ * Rendering methods * /
STDMETHOD (DRAW) PURE Download Addition (THIS_ HDC HDC, Struct TagRect Far * PrcBounds) Pure;
STDMETHOD (TILE) (THIS_ HDC HDC, Struct Tagpoint Far * PPTBackorg, Struct TagRect Far * Prclip, Struct Tagsize Far * psize) PURE
StdMethod (This_ HDC HDC, Int Dstx, Int Dsty, Int Dstxe, Int Dstye, Int Srcx, Int Srcy, Int Srcxe, Int Srcy, DWORD DWROP) PURE
}
From the interface, after creating the IIMGCTX interface object, you can use the LOAD method to transfer the image file. After the decoding is complete, you can use the DRAW method to display, but:
The parameters in the LOAD method indicate that a URL (estimated is the requirements of the IE kernel), so you need to convert the local file name to the file: // out of the URL, and must use Unicode encoding. Like other interfaces in IE, the IIMGCTX work process is also asynchronous, so it is necessary to set the setcallback method to set the callback function, and the SELECTCHANGES method monitors the status, but because of what information is not found, I don't know how these two interfaces use. I only know that this asynchronous process must create a message pump, distribute the messages generated during the decoding process, otherwise the decoding process will be hung. The DRAW method allows access to an HDC as a target DC, and if this HDC is a memory DC, it may not be displayed, and the image is decoded directly in the memory. The decoded image is DDB, and then conventional image processing can be performed after converting into DIB.
See the wndimgctx.cpp in the instance file with the detailed process of decoding with IIMGCTX. Third, how do you integrate an instance source code into the VC project?
The instances provided herein are included in IMGViewer.zip, and it is a complete VC 6 project after unlocking. In addition to the code to decode the image with IIMGCTX, there is also an instance code for searching, sorting, and implementing the files in the directory in the directory.
If you only need to use the image decoding portion, put wndimgctx.h, wndimgctx.cpp, in your project, start to join: Decoding CPP file:
#include "wndimgctx.h"
Then you can call
Hbitmap getBitmapfromfile (LPCTSTR PSZFileName);
The function is decoded. As can be seen from the function prototype, this function passes into a file path, returns a DDB handle.
If you need to include all images in the order display directory, use srchdir.h, srchdir.cpp, dirmng.h, dirmng.cpp to your project, see the relevant code in Mainfrm.cpp.
From the effect of use, in Windows 98 / Me, there is a problem when IIMGCTX decoding the TIFF file. There are also a few articles on the MSDN discussing the article that does not show TIFF in 98 / me. Set, it seems still not. There is no problem in Windows 2000 / XP.
4. Why is the TIFF file an exception?
IE almost supports all common image formats, including JPEG, PNG, GIF, etc., but not see TIFF in the "Open File" dialog box of IE. I use the Tiff image example provided by the libTIFF organization, and the image browser instance provided herein is found. It is found that in 98 / me / XP, a TIFF file is not open; in Windows 2000, it can open almost half, the other half not open.
Under Windows 2000, press DEBUG mode in VC 6, run ImageViewer, open TIFF files, exit, and you can see the following line in the Output window:
Loaded 'c: /winnt/system32/imgutil.dll', no matching symbolic information found.
Loaded 'c: /winnt/system32/tifflt.dll', no matching symbolic information found.
Loaded 'c: /winnt/system32/oieng400.dll', no matching symbolic information found.
Loaded 'c: /winnt/system32/mscms.dll', no matching symbolic information found.
Loaded 'c: /winnt/system32/winspool.drv', no matching symbolic information found.
And under Windows XP, only the first line can be seen, there is no subsequent row.
In Windows 2000, run the regedit, then search for Tifflt.dll, you can see it provides "TiffilTer Class", CLSID is {EBD0F6B6-4AED-11D1-9CDB-00805F0C62F5}. Continue to search this CLSID in regedit32, you can see image filter clsid in the hkey_classes_root / mime / database / content type / image / TIFF item. In front of this item, there are image / png, image / jpeg, etc., which have image filter clsid. The documentation provided from MSDN can be known that all MIME TYPEs that IE can identify under the hkey_classes_root / mime / data / content type, MIME TYPE generally extracts from the HTML cladding head returned from the web server. From the name of Image Filter CLSID, this CLSID record should be the CLSID of the image decoder. Run the regedit32 under Windows 98 / ME / XP, find the hkey_classes_root / mime / database / content type / image / TIFF item, and there is no image filter clsid. And under Image / PNG, Image / JPEG and other items have this key. This is probably why IE cannot decode TIFF files under Windows 98 / ME / XP: there is no corresponding decoder.
I have tried to move Tifflt.dll to Windows XP, but because of the conflict of the DLL, there is no success. It seems that you want to display the TIFF file under the Windows platform other than 2000, only waiting for Microsoft to introduce the corresponding TIFF decoder.
V. Further practice
Although the instance code demonstrates the most original function of an image browser, it is necessary to be a real image browser, there are many places that need to be improved. If you are interested, you can try it, it is exercised: