To read BMP images from devices and display them in the dialog box. It was quite simple, but there were various problems ......
Looking at the code written by the predecessors, we found that most of them use LoadImage, but they did not read the file. Debugging found that the h_bmp handle is null, that is, an error is reported. Getlasterror () found that the error returned value is 1814, the specified resource name cannot be found in the image file. Later I found that LoadImage is actually a method in VC, while EVC uses shloaddibitmap ......
Summary:
There are three types of methods for reading and displaying BMP files.
1. As part of a resource (resouce), a BMP image is a bitmap with a resource ID added to the resouceview of EVC. You can use
Hbitmap h_bmp;
H_bmp = loadbitmap (afxgetapp ()-> m_hinstance, makeintresource (idb_bitmap1 ));
This method.
2. BMP images are stored on devices and are randomly loaded (dynamically read). I 've been doing this for a long time. Most of them use the LoadImage function on the Internet, but it remains unreadable for a long time. Later I saw a saying that EVC uses shloaddibitmap. I tried it and succeeded ~~
3. For the first two methods, only reading and displaying are implemented, and the image itself is not processed. To process the image itself, you must read and modify the content of the BMP file. This part involves the file structure and so on, it is more troublesome.
The final implementation code is as follows:
Cfiledialog filedlg (true );
Filedlg. m_ofn.lpstrtitle = _ T ("topographic map reading ");
Filedlg. m_ofn.lpstrfilter = _ T ("BMP files (*. BMP)/0 *. BMP/0/0 ");
If (idok = filedlg. domodal ())
{
M_strfile = filedlg. getpathname ();
Hbitmap h_bmp;
Hinstance = AfxGetInstanceHandle ();
H_bmp = shloaddibitmap (m_strfile );
If (h_bmp = NULL)
{
Error = getlasterror ();
}
Pwinshow-> modifystyle (0xf, ss_bitmap | ss_centerimage );
Pwinshow-> setbitmap (h_bmp );
}