我正在嘗試學習 gdiplus windows API,特別是如何使用 GraphicsPath 從不同形狀中獲取點。我注意到我永遠無法從微軟的示例代碼中得到任何東西,所以我試著看看有多少點實際上是在這樣的 GraphicsPath 中:
#include <windows.h>
#include <gdiplus.h>
#include <iostream>
//use gdiplus library when compiling
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
VOID GetPointCountExample()
{
// Create a path that has one ellipse and one line.
GraphicsPath path;
path.AddLine(220, 120, 300, 160);
// Find out how many data points are stored in the path.
int count = path.GetPointCount();
std::cout << count << std::endl;
}
int main()
{
GetPointCountExample();
}
這總是回傳計數 0。這是為什么呢?
我嘗試使用 mingw-64 和 Visual Studio 進行編譯,結果相同。
我還嘗試列印出由此回傳的 Gdiplus::Status:
GraphicsPath path;
int stat = path.StartFigure();
std::cout << stat << std::endl;
即使 StartFigure 不帶引數,它也會列印狀態 2,“InvalidParameter”。
uj5u.com熱心網友回復:
啊閱讀更多檔案并發現:The GdiplusStartup function initializes Windows GDI . Call GdiplusStartup before making any other GDI calls
https ://docs.microsoft.com/en-us/windows/win32/api/Gdiplusinit/nf-gdiplusinit-gdiplusstartup
此代碼有效:
#include <windows.h>
#include <gdiplus.h>
#include <iostream>
//use gdiplus library when compiling
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
VOID GetPointCountExample()
{
// Create a path that has one ellipse and one line.
GraphicsPath path;
path.AddLine(0, 0, 0, 1);
// Find out how many data points are stored in the path.
int count = path.GetPointCount();
std::cout << count << std::endl;
}
int main()
{
//Must call GdiplusStartup before making any GDI calls
//https://docs.microsoft.com/en-us/windows/win32/api/Gdiplusinit/nf-gdiplusinit-gdiplusstartup
ULONG_PTR token;
GdiplusStartupInput input;
input.GdiplusVersion = 1;
input.SuppressBackgroundThread = false;
GdiplusStartup(&token, &input, NULL);
GetPointCountExample();
//Shutdown GDI when finished using
GdiplusShutdown(token);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/449964.html
