Generally, image processing software creates a thumbnail list for the image files read into the program, like ACDSee. Recently, I am working on an image processing project. The raw data processed is an image file. I want to create a thumbnail from the very beginning of the project, but I have been suffering from limited technical skills and time is not allowed. In the last two days, I spent some time on Google and Baidu, and carefully studied the implementation of thumbnails. In fact, using VC ++ to implement a thumbnail is not complicated. There are two steps: 1. Create the clistctrl control and cimagelist image list, and set their respective attributes. 2. make the thumbnail of the image file you want to display and add it to the cimagelist file as a bitmap file. Then, set each image file as an item and insert it into clistctrl to complete the thumbnail creation. For the rest, you can write the processing methods for each message to respond to your operations on the thumbnail.
It's easy to say, but I encountered a lot of trouble when implementing it myself. The biggest trouble is how to make thumbnails in the memory, how to Make thumbnails of each image file into Bitmap bitmap resources (because cimagelist can only be added to bitmap resources ). I have been operating in the memory for half a day, but I still fail. In addition, the biggest problem is that due to the color palette in the memory, the images drawn in the memory are black and white. Finally, I thought of the cximage image processing library applied in our project. I carefully read the document of this library, which is called "getting lost without a pair of shoes is free of effort." I found that the method provided by this library is very easy to implement thumbnails. The principle is still this principle. After cximage is applied, the original problems are resolved one by one, and the original operations are simpler. Below we will post the implementation process and code to help readers.
The effect achieved by the Program:
1. Create the clistctrl control and cimagelist image list, and set their respective attributes. For my program, I dynamically created the clistctrl control and cimagelist image list in oncreate in the view on the left of the graph.
Int cworkspacebar: oncreate (maid) {If (cbcgpdockingcontrolbar: oncreate (lpcreatestruct) =-1) Return-1; crect rectdummy; rectdummy. setrectempty (); // create tree windows. // dynamic production list control and image list m_listctl.create (lvs_icon | ws_child | ws_visible | lvs_typemask, crect (150,500, 100), this,); m_myimagelist.create (64, 64, ilc_color24, 0, 1); Return 0 ;}
2. design a left-side view method so that we can call this method in the document class to add items to the left-side view, the task to be completed is to prepare Bitmap (Bitmap Resource) for each image file in the memory ).
The Code is as follows:
Void cworkspacebar: initiallistctrl (INT imagecount, cstring * pimagenamelist) // controls the list initialized Based on the read document data // input parameter imagecount is the total number of image files, pimagenamelist is the name list of each image file in sequence {// Save the document data m_imagecount = imagecount; m_pimagenamelist = pimagenamelist; // apply cximage to dynamically generate a specified-size bitmap cximage image in the memory; // declare the cximage object for (INT I = 0; I <imagecount; I ++) {// apply cximage to load the image. This program is a relative path image. load (pimagenamelist [I], cximage_format_bmp); // apply cximage to convert the image to The size is 96*96. When cimagelist is declared earlier, it is the 96*96 image. resample (, 2); // application cximage in memory to produce bitmap CDC * PDC = getdc (); hbitmap hbit = image. makebitmap (PDC-> getsafehdc (); cbitmap BMP; BMP. attach (hbit); // Add the bitmap to the image list m_myimagelist.add (& BMP, RGB (255,255,255); BMP. detach () ;}// associate the image list with the list control m_listctl.setimagelist (& m_myimagelist, lvsil_normal); // set the lvitem items of the list control; item. mask = lvif_text | lvif_image; item. iItem = 0; /// 1st Item. isubitem = 0; // main item. psztext = ""; item. iimage = 0; // set the index value of the specified image in the associated image list m_listctl.insertitem (& item); // Add 1st items m_listctl.setitemtext (, pimagenamelist [0]); for (I = 1; I <imagecount; I ++) {item. iItem = I; // prepare to add the item. iimage = I; inline (& item); m_listctl.setitemtext (I, 0, pimagenamelist [I]);} DWORD dwoldstyle, dwnewstyle; dwnewstyle = lvs_icon; hwnd hwndlt = inline (); // obtain The window handle dwoldstyle = getwindowlong (hwndlt, gwl_style) of the List View control; // obtain the window style of the List View control if (dwoldstyle & lvs_typemask )! = Lvs_icon) // determines whether the current display mode is the specified mode {dwoldstyle & = ~ Lvs_typemask; // shield unnecessary information from the old window style dwnewstyle | = dwoldstyle; // keep the other style of the window unchanged, and only change the display mode setwindowlong (hwndlt, gwl_style, dwnewstyle); // change the window style of the list control }}
The rest of the work is to write the processing method of each message, including clicking the corresponding thumbnail to display each image in the corresponding view.
Summary: This program is based on the cximage image processing library. Cximage is a good image processing library, which can be easily accessed online and open-source. I believe that cximage is better than GDI and GDI +. This program is successfully debugged in VC ++ 6.0 and runs well.