Example: how to convert a format to another format
Cximage image;
// BMP-> JPG
Image. Load ("image.bmp", cximage_format_bmp );
If (image. isvalid ()){
If (! Image. isgrayscale () image. increasebpp (24 );
Image. setjpegquality (80 );
Image. Save ("image.jpg", cximage_format_jpg );
}
// PNG-> TIF
Image. Load ("image.png", cximage_format_png );
If (image. isvalid ()){
Image. Save ("image. tif", cximage_format_tif );
}
How to load images from resources
// Load the resource idr_png1 from the PNG Resource Type
Cximage * newimage = new cximage ();
Newimage-> loadresource (findresource (null, makeintresource (idr_png1 ),
"PNG"), cximage_format_png );
Or
// Load the resource idr_jpg1 from DLL
Cximage * newimage = new cximage ();
Hinstance hdll = loadlibrary ("imagelib. dll ");
If (hdll ){
Hrsrc hres = findresource (hdll, makeintresource (idr_jpg1), "jpg ");
Newimage-> loadresource (hres, cximage_format_jpg, hdll );
Freelibrary (hdll );
}
Or
// Load a bitmap resource;
Hbitmap bitmap =: loadbitmap (AfxGetInstanceHandle (),
Makeintresource (idb_bitmap1 )));
Cximage * newimage = new cximage ();
Newimage-> createfromhbitmap (Bitmap );
How to decode images in memory
Cximage image (byte *) buffer, size, image_type );
Or
Cxmemfile memfile (byte *) buffer, size );
Cximage image (& memfile, image_type );
Or
Cxmemfile memfile (byte *) buffer, size );
Cximage * image = new cximage ();
Image-> decode (& memfile, type );
How to encode images in memory
Long size = 0;
Byte * buffer = 0;
Image. encode (buffer, size, image_type );
...
Image. freememory (buffer );
Or
Cxmemfile memfile;
Memfile. open ();
Image. encode (& memfile, image_type );
Byte * buffer = memfile. getbuffer ();
Long size = memfile. Size ();
...
Image. freememory (buffer );
How to create a multi-page tiff
Cximage * pimage [3];
Pimage [0] = & image1;
Pimage [1] = & image2;
Pimage [2] = & image3;
File * hfile;
Hfile = fopen ("multipage. tif", "W + B ");
Cximagetif multiimage;
Multiimage. encode (hfile, pimage, 3 );
Fclose (hfile );
Or
File * hfile;
Hfile = fopen ("C: // multi. tif", "W + B ");
Cximagetif image;
Image. Load ("C: // 1.tif", cximage_format_tif );
Image. encode (hfile, true );
Image. Load ("C: // 2.bmp", cximage_format_bmp );
Image. encode (hfile, true );
Image. Load ("C: // 3.png", cximage_format_png );
Image. encode (hfile );
Fclose (hfile );
How to copy and paste Images
// Copy)
Handle hdib = image-> copytohandle ();
If (: openclipboard (afxgetapp ()-> m_pmainwnd-> getsafehwnd ())){
If (: emptyclipboard ()){
If (: setclipboarddata (cf_dib, hdib) = NULL ){
Afxmessagebox ("unable to set Clipboard data ");
}}}
Closeclipboard ();
// Paste (paste)
Handle hbitmap = NULL;
Cximage * newima = new cximage ();
If (openclipboard () hbitmap = getclipboarddata (cf_dib );
If (hbitmap) newima-> createfromhandle (hbitmap );
Closeclipboard ();
How to display images in the image box control (picture box)
Hbitmap m_bitmap = NULL;
Cximage image ("myfile.png", cximage_format_png );
...
CDC * HDC = m_picture.getdc ();
Hbitmap m_bitmap = image. makebitmap (HDC-> m_hdc );
Hbitmap holdbmp = m_picture.setbitmap (m_bitmap );
If (holdbmp) deleteobject (holdbmp );
If (HDC-> m_hdc) m_picture.releasedc (HDC );
...
If (m_bitmap) deleteobject (m_bitmap );
Post-translated order:
Regarding image processing libraries, I believe everyone has a common question: How can I choose so many image processing libraries? I have answered this question thoroughly in the csdn blog. Thanks to the author for his thorough explanation:
The cximage class library is an excellent image operation class library. It can quickly access, display, and convert various images. Some readers may say that there are so many excellent graphics libraries, such as openil, freeimage, and paintlib. They are powerful and complete, and there is no need to use other class libraries. However, I would like to say that these class libraries are basically not free of charge. To use these class libraries, you must be bound by such a license agreement.
The cximage class library is free of charge. In addition, you may encounter a lot of trouble when using the above class libraries. Because most of them are platform-independent and are written in C language, some are also mixed with the basic C ++ wrapper and heap German compilation option declarations that need to be processed by you. The cximage class library is doing well in this regard. What makes me most optimistic is that the source code is completely disclosed by the author. Compared with those encapsulated graphics libraries and GDI +, this allows us to further study various coding and decoding technologies, instead of floating on the surface of various technologies. "