In fact, this is no use, after all, is outdated technology. However, the technical update with the actual use or there is a gap, unavoidable or to use this outdated technology, so it is recorded, convenient for later inspection.
GDI + is not mistaken for the birth of the following XP, is the graphics system on the XP system (formerly GDI), GDI + compared to GDI provides a number of new features, such as gradient brush, support a variety of image formats and so on. But I think the biggest change is the change in the programming model. GDI + uses object-oriented thinking, the interface is packaged in class, the use of more convenient.
Using the GDI + library in your application should follow the steps:
1. Contains the Gdiplus.h header file, if the diagram is convenient, plus: using namespace Gdiplus, so you do not need to re-specify the namespace with anything in GDI +.
2. Link DLL's import library Gdiplus.lib. There are two ways to do this in VS, one is to fill in the Gdiplus.lib directly in the project properties------input, and the second is to use the compiler primitive directly: #pragma comment (lib, "Gdiplus.lib")
3. Be sure to call the GDI + library initialization function Gdiplusstartup () before calling any GDI + functions to initialize the GDI + library.
4. When determining that no GDI + functions are required and that all GDI + objects have been destroyed (the variable exceeds the lifetime), you need to call the GDI + shutdown function Gdiplusshutdown (). GDI + supports multi-threading, so it can be called in any one of the threads.
Below is the actual MFC single/multiple file program, how to use the GDI + Graphics system (program named: gdiplustest).
1. Add the following code to the Stdafx.h header file
#include <GdiPlus.h>
#pragma comment (lib, "Gdiplus.lib")
2. In the Cgdiplustestapp class, add two variables for the GDI + initialization function.
Private
Gdiplus::gdiplusstartupinput Gdiplusstartupinput;
ULONG_PTR Gdiplustoken;
3. Add the following code in the Cgdiplustestapp::initinstance () function, before Pmainframe->showwindow (m_nCmdShow), it is recommended to add the CWINAPPEX::I After Nitinstance ().
Initialize GDI +.
Gdiplus::gdiplusstartup (&gdiplustoken, &gdiplusstartupinput, NULL);
4. Reload the Cgdiplustestapp ExitInstance () function, and then add the GDI + Close function.
Gdiplus::gdiplusshutdown (Gdiplustoken);
5. Use the GDI + class in the Cgdiplustestview::ondraw (cdc* PDC) function to display the picture lena.jpg
Gdiplus::graphics Graphics (PDC->GETSAFEHDC ());
Gdiplus::image Image (L "lena.jpg");
Graphics. DrawImage (&image, 10, 10);