GDI + Usage Guide (basic guiding of GDI Plus)

Source: Internet
Author: User

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

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.