Various problems encountered in EVC programming-BMP files

Source: Internet
Author: User
Tags bmp image

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 );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.