Now, let me explain the simple usage of this cximage class, hoping to help those who are new to cximage, first, I want to explain that here I take cximage 6.0.0.0 as an example (each version may be different ). Official: http://www.xdp.it/cximage/
After opening the project, you can see the following examples of projects:
-Cximage
-Cximagecrtdll
-Cximagemfcdll
-Dome
-Domedll
-Jasper
-JBIG
-JPEG
-Libdcr
-MNG
-PNG
-Tiff
-Zlib
1. First, make sure thatProgramI suggest you use dynamic links because the library is a bit large. If you use static links, your application volume will increase by more than 1 MB.
2. Then, determine whether to use it in MFC or in the CRT environment. This library is dedicated to creating these two projects for you to create runtime libraries used in different environments, and choose to compile according to your needs.CximagecrtdllOrCximagemfcdllProject. If you want to use the static Library Link, you do not need to compile other projects except the two projects. When referencing this static library, copy all the *. Lib files in these compiled projects to your program.
3. OK. After compiling the project, copy the following files to the project you created.
Copy the header file to your project:
XFile. H, ximacfg. H, ximadef. H, ximage. H, xiofile. H, xmemfile. h
To use static links, copy the following files:
Cximage. Lib, PNG. Lib, JPEG. Lib, JBIG. Lib, Tiff. Lib, libdcr. Lib, Jasper. Lib, zlib. Lib, MNG. Lib
Copy the following files to use dynamic links:
Cximage. Lib, cximage. dll
4. Reference this library # include "ximage. H ", # pragma comment (Lib," cximage. lib ") for those copied from static links *. all lib files must be referenced or cannot be linked. Here, someone may ask if only "ximage. H "Why should I copy this header file so many files? This is because the header file "ximage. H" depends on the header files, so it must be copied.
5. Now you can use this cximage library. Let's load an image and display it:
Cximage image; // defines a cximage object
Image. Load ("ooopsy.png", cximage_format_png); // load a PNG Image
// Display it in the onpaint message
Image. Draw (DC. getsafehdc (), 0, 0 );
This is the document start page. If you need it, go and check it out!
Specific Application Skills
1. Open a picture
You can create a new cximage object to open a graph by using the constructor.
Cximage: cximage (const char * filename, DWORD imagetype)
Here, filename is the file path to be opened and imagetype is the file type. The supported types include:
Metrics, cximage_format_bmp, cximage_format_gif, metrics, cximage_format_ico, cximage_format_tif, cximage_format_tga, metrics, cximage_format_ras,
Of course, it is hard to remember that we can use the following functions to directly obtain the file format.
Int findtype (const cstring & filename)
{
Cstring ext = filename. Right (filename. getlength ()-filename. reversefind ('.')-1 );
Int type = 0;
If (EXT = "BMP") type = cximage_format_bmp;
# If cximage_support_jpg
Else if (EXT = "jpg" | ext = "Jpeg") type = cximage_format_jpg;
# Endif
# If cximage_support_gif
Else if (EXT = "GIF") type = cximage_format_gif;
# Endif
# If cximage_support_png
Else if (EXT = "PNG") type = cximage_format_png;
# Endif
# If cximage_support_mng
Else if (EXT = "MNG" | ext = "jng") type = cximage_format_mng;
# Endif
# If cximage_support_ico
Else if (EXT = "ICO") type = cximage_format_ico;
# Endif
# If cximage_support_tif
Else if (EXT = "tiff" | ext = "TIF") type = cximage_format_tif;
# Endif
# If cximage_support_tga
Else if (EXT = "TGA") type = cximage_format_tga;
# Endif
# If cximage_support_pcx
Else if (EXT = "PCX") type = cximage_format_pcx;
# Endif
# If cximage_support_wbmp
Else if (EXT = "wbmp") type = cximage_format_wbmp;
# Endif
# If cximage_support_wmf
Else if (EXT = "WMF" | ext = "EMF") type = cximage_format_wmf;
# Endif
# If cximage_support_j2k
Else if (EXT = "j2k" | ext = "JP2") type = cximage_format_j2k;
# Endif
# If cximage_support_jbg
Else if (EXT = "jbg") type = cximage_format_jbg;
# Endif
# If cximage_support_jp2
Else if (EXT = "JP2" | ext = "j2k") type = cximage_format_jp2;
# Endif
# If cximage_support_jpc
Else if (EXT = "JPC" | ext = "j2c") type = cximage_format_jpc;
# Endif
# If cximage_support_pgx
Else if (EXT = "pgx") type = cximage_format_pgx;
# Endif
# If cximage_support_ras
Else if (EXT = "RAS") type = cximage_format_ras;
# Endif
# If cximage_support_pnm
Else if (EXT = "PNM" | ext = "PGM" | ext = "ppm") type = cximage_format_pnm;
# Endif
Else type = cximage_format_unknown;
Return type;
}
2. Save a figure
bool cximage: Save (lpcwstr filename, DWORD imagetype = 0)
the parameters are the same as those above.
3. Obtain the graphic data to use the material in OpenGL
byte * cximage: getbits (dword row = 0 );
4. Obtain the image size
long getsize ();
5. Obtain the image height and width
DWORD cximage: getheight ();
DWORD cximage: getwidth ();
6. file type
DWORD cximage: GetType () const;
7. Get the last error
char * cximage: getlasterror ();
8. Draw the result on the Interface
long cximage :: draw (HDC, const rect & rect, rect * pcliprect = NULL)
HDC drawing device, rect drawing area, determine the upper left corner and lower right corner coordinates of the drawing. Pcliprect, crop area, usually the same size as the drawing area, unless otherwise required.