vc++ 怎么用gdi画数字,要求数字颜色、旋转、大小 都是可以变动的如下图示,可以做到吗 ,怎么做的? 30
展开全部
#include <tchar.h>
#include <Windows.h>
#include <gdiplus.h>
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
void DrawRotateText(Graphics& g, LPWSTR s, int len, const Font& f, const Color& c, int x, int y, double rotate)
{
Matrix trans;
StringFormat sf;
RectF rf;
g.MeasureString(s, len, &f, PointF(x, y), &sf, &rf);
SizeF siz;
rf.GetSize(&siz);
trans.Reset();
trans.RotateAt(rotate, PointF(x + siz.Width / 2, y + siz.Height / 2));
g.SetTransform(&trans);
g.DrawString(s, len, &f, PointF(x, y), &sf, &SolidBrush(c));
trans.Reset();
g.SetTransform(&trans);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_NCDESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
{
Graphics g(hdc);
Font font(L"Arial", 24);
DrawRotateText(g, L"1", 1, font, Color(44, 16, 89), 45, 35, 0);
DrawRotateText(g, L"7", 1, font, Color(243, 60, 8), 145, 35, 0);
DrawRotateText(g, L"8", 1, font, Color(13, 143, 89), 245, 35, -45);
DrawRotateText(g, L"6", 1, font, Color(5, 138, 226), 45, 115, 0);
DrawRotateText(g, L"4", 1, font, Color(250, 131, 18), 145, 115, -45);
DrawRotateText(g, L"3", 1, font, Color(40, 16, 96), 245, 115, 0);
DrawRotateText(g, L"5", 1, font, Color(26, 145, 88), 45, 195, -45);
DrawRotateText(g, L"9", 1, font, Color(237, 199, 43), 145, 195, 0);
DrawRotateText(g, L"2", 1, font, Color(236, 52, 6), 245, 195, 0);
g.Flush();
}
EndPaint(hwnd, &ps);
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
INT APIENTRY _tWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR tszCmd, INT nShow)
{
GdiplusStartupInput gsi;
ULONG_PTR t;
GdiplusStartup(&t, &gsi, NULL);
LPCTSTR szClsName = _T("MyWindow");
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.hInstance = hInst;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpszClassName = szClsName;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClass(&wc);
HWND hwnd = CreateWindow(szClsName, _T("数字"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL);
POINT p;
p.x = 0;
p.y = 0;
ClientToScreen(hwnd, &p);
RECT rect;
rect.left = p.x;
rect.top = p.y;
rect.right = p.x + 320;
rect.bottom = p.y + 240;
AdjustWindowRect(&rect, GetWindowLong(hwnd, GWL_STYLE), FALSE);
MoveWindow(hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while( GetMessage(&msg, 0, 0, 0) > 0 ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(t);
return 0;
}
勉强用gdi+写了一个出来,虽然不是GDI不过运行出来结果有点那么回事
追答
你d:\imageN.jpg几个文件也是相同的吗?
如果response返回的是相同的还说可能是浏览器缓存啊之类的问题,文件呢
另外就是你要不要拿C#创建一个控制台程序或者窗口程序,把这段代码单独拿出来跑跑看
展开全部
你还没解决啊?给你个GDI的文章看看,里面详细介绍了各种画法,里面有个图片旋转画法:
http://www.codeproject.com/Articles/251892/Guide-to-Image-Composition-with-Win32-MsImg32-dll
http://www.codeproject.com/Articles/251892/Guide-to-Image-Composition-with-Win32-MsImg32-dll
追问
嗯,又碰到你了,看来太有缘了,你要帮帮我解决啊,天哪,全是英文,不行我看不懂。
追答
呵呵,英文是你总要突破的难关,多下点狠手学习吧。这篇文章是很不错的,学会了,你就知道很多画法了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询